Buenas a todos!!!
Seguinte estou tendo um problema com relação ao carregamento das classes, pois não consigo descarregar mais.
Estou usando a JavaComm 3.0 no linux suse, ótimo ela funciona muito bem obrigado, mas tem um problema, que junto com ela, estou utilizando dispositivos seriais plugaveis, ou seja, um conversor usb-serial, no entanto hora que carrego o programa creio eu que o comm.jar seja criado juntamente com meu objeto, tenho um objeto que utiliza ela.
Depois que eu estou rodando, acho que o driver ja esta carregado e caso eu não tenha plugado o dispositivo, não acha a nova porta com o método getPortIdentifiers().
ótimo, a melhor solução que achei foi:
//you have to tell the loader where to find the class since its going to have to do this from scratch - without the help of system loader.
String class_path = System.getProperty(“java.ext.dirs”) + System.getProperty(“file.separator”) + “comm.jar”;
System.out.println(class_path);
URL class_path_url = new File(class_path).toURL();
URLClassLoader tempLoader = new URLClassLoader(new URL[]{class_path_url}); //create a new URLClassLoader
Method findClass_Method = URLClassLoader.class.getDeclaredMethod(“findClass”, new Class[]{String.class}); //get the method findClass(String name)
findClass_Method.setAccessible(true); //unprotect the method
Class loaded = (Class) findClass_Method.invoke(tempLoader, new Object[]{“javax.comm.CommPortIdentifier”} ); //call it as if it was the member method of a new URLClassLoader object. If this call succeeds, it should return the Class object for the class.
//use the class by extracting its methods and invoking them by using reflection.
//loaded.getDeclaredMethod("finalize", new Class[0]).invoke(null); //now that you have the CommPortIdentifier class object, you can call its methods
lista=(Enumeration)loaded.getDeclaredMethod("getPortIdentifiers", new Class[0]).invoke(null); //now that you have the CommPortIdentifier class object, you can call its methods
lista=(CommPortIdentifier.getPortIdentifiers());
loaded = null; //release the class to avoid memory leak
porém creio que pelo metodo getPortIdentifiers, ou algum utlizado pela classe ser static, ele sobre carrega, ou seja, roda mais de uma vez e vai acumulando as portas!!! exemplo:
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3
/dev/ttyS4
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3
/dev/ttyS4
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3
/dev/ttyS4
/dev/ttyS0
/dev/ttyS1
/dev/ttyS2
/dev/ttyS3
/dev/ttyS4
/dev/ttyUSB0
note que ele pode obter a porta USB a algum momento, mas vai sobrecarregando o vetor do metodo.
o que eu gostaria de fazer não sei c tem como em run-time, mas creio que pelo pode do java sim, mas não sei nem como.
gostaria de descarregar o driver e recarregar, mais ou menos como acontece no metodo que apresentei.
alguem poderia me ajudar, ou ja passou por isso…