Native Library /tmp/sp_tuartx1/spcomlnxx64.so already loaded in another classloader with servlet

1 view
Skip to first unread message

rucko24

unread,
Aug 28, 2017, 10:00:28 PM8/28/17
to SerialPundit
Regards, how are you? I have a web application with java using vaadin framework, when I make a change in my code and restart my servlet I get this log, Everything returns to work correctly when, to completely my jetty or wildfly server, and I start again

com.serialpundit.core.SerialComException: Native Library /tmp/sp_tuartx1/spcomlnxx64.so already loaded in another classloader at com.serialpundit.serial.internal.SerialComPortJNIBridge.loadNativeLibrary(SerialComPortJNIBridge.java:395) at com.serialpundit.serial.SerialComManager.<init>(SerialComManager.java:382)


And the creator of this great driver I recommend using this constructor,

SerialComManager(String loadedLibName, String directoryPath, final boolean createDirectory, boolean hotDeploy)


Create a directory in my /home/serialPundit/spcomlnxx64.so but still not working

Rishi Gupta

unread,
Aug 28, 2017, 10:33:39 PM8/28/17
to SerialPundit
Please set hotDeploy to true and then try.

rucko24

unread,
Aug 28, 2017, 10:47:19 PM8/28/17
to SerialPundit

 private static final long serialVersionUID = 1L;
 
private static SerialPundit instance;
 
private static final String PORT_SERIAL = "/dev/ttyS0";
 
private static final String PATH_NAME = "/home/rubn/serialPundit";
 
private static final String LIB_NAME = "spcomlnxx64";
 
 
private SerialPundit(){}
 
public static synchronized SerialPundit getInstance() {
 
if(instance == null) {
 instance
= new SerialPundit();
 
}
 
return instance;
 
}
 
public void init(String onOff) {
 
try {
 
SerialComManager scm = new SerialComManager(LIB_NAME , PATH_NAME, true, true);
 
//SerialComManager scm = new SerialComManager();  
 
long handle = scm.openComPort(PORT_SERIAL, true, true, false);
 scm
.configureComPortData(handle, DATABITS.DB_8, STOPBITS.SB_1, PARITY.P_NONE, BAUDRATE.B9600, 0);
 scm
.configureComPortControl(handle, FLOWCONTROL.NONE, 'x', 'x', false, false);
 
 
if(onOff.equals("1")) {
 scm
.writeString(handle,"1", 0);
 
}else {
 scm
.writeString(handle,"2", 0);
 
}
 
 
String data = scm.readString(handle);
 
System.out.println("data read is :" + data);
 scm
.closeComPort(handle);
 
 
}catch (Exception e) {
 e
.printStackTrace();
 
}
 
}
}



java.lang.UnsatisfiedLinkError: com.serialpundit.serial.internal.SerialComPortJNIBridge.initNativeLib()I
at com.serialpundit.serial.internal.SerialComPortJNIBridge.initNativeLib(Native Method)
at com.serialpundit.serial.SerialComManager.<init>(SerialComManager.java:481)
at com.Core.vaadin.arduino.clasesSerialArduino.SerialPundit.init(SerialPundit.java:32)
at com.Core.vaadin.arduino.bombilla.PanelArduinoOnOff.lambda$0(PanelArduinoOnOff.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 

Rishi Gupta

unread,
Aug 28, 2017, 11:09:33 PM8/28/17
to SerialPundit
- Let us divide problems into individual pieces. We need to separate serialpundit issue, hot deployment issue, your app programming related issue, and singleton related issue.

- Is test https://github.com/RishiGupta12/SerialPundit/blob/master/tests/test92-hot-deploy/src/test92/Test92.java passing for you in you environment. Running 4-5 times with hot deployment of servlet.

- For the code you shared try removing static instance of SerialPundit (instance variable).

rucko24

unread,
Aug 29, 2017, 12:01:13 AM8/29/17
to SerialPundit
I still get the same error.

GRAVE:
java
.lang.UnsatisfiedLinkError: com.serialpundit.serial.internal.SerialComPortJNIBridge.initNativeLib()I
 at com
.serialpundit.serial.internal.SerialComPortJNIBridge.initNativeLib(Native Method)

 at com
.serialpundit.serial.SerialComManager.<init>(SerialComManager.java:481)

rucko24

unread,
Aug 29, 2017, 1:26:04 PM8/29/17
to SerialPundit
public class SerialPundit implements Serializable {


 
private static final long serialVersionUID = 1L;

 
private static final String PORT_SERIAL = "/dev/ttyACM0";

 
private static final String PATH_NAME = "/home/rubn/serialPundit";
 
private static final String LIB_NAME = "spcomlnxx64";

 
 
public SerialPundit() {

 
 
}
 
public void init(String onOff) {
 
try {
 
SerialComManager scm = new SerialComManager(LIB_NAME , PATH_NAME, true, true);

 
String[] ports = scm.listAvailableComPorts();
 
for(String port: ports){
 
System.out.println(port);
 
}
 
/*long handle = scm.openComPort(PORT_SERIAL, true, true, false);

 scm.configureComPortData(handle, DATABITS.DB_8, STOPBITS.SB_1, PARITY.P_NONE, BAUDRATE.B9600, 0);
 scm.configureComPortControl(handle, FLOWCONTROL.NONE, 'x', 'x', false, false);
 
 if(onOff.equals("1")) {
 scm.writeString(handle,"1", 0);
 }else {
 scm.writeString(handle,"2", 0);
 }
 String data = scm.readString(handle);
 System.out.println("data read is :" + data);
 scm.closeComPort(handle);*/
 
 
}catch (Exception e) {
 e
.printStackTrace();
 
}
 
}













This is my current code. And the error persists :s

java.lang.UnsatisfiedLinkError: com.serialpundit.serial.internal.SerialComPortJNIBridge.initNativeLib()I



Rishi Gupta

unread,
Aug 30, 2017, 9:50:07 PM8/30/17
to SerialPundit
Hi, I tested and found that I have forgotten that the test is intended to be run in tomcat hot deployment scenario, so it may fail on desktop.

When you run hot deployment scenario (not restart server but just application is restarted) the class which loads native shared library does not load the library again as it has been already loaded very 1st time when app was started.


Can you help me debug in your environment. I have shared a jar with added logs to see exactly at what step prevention of loading of shared library occurs.

Run in webapp not in desktop (test92 not needed).

rucko24

unread,
Aug 31, 2017, 12:47:23 PM8/31/17
to SerialPundit
Thank you very much, thank you, I have always executed that contructor from jetty and wildfly, I will try your sptty.rar

rucko24

unread,
Aug 31, 2017, 12:55:13 PM8/31/17
to SerialPundit
I was also using this dependency in maven, now, with the sptty.jar I do not recognize the SerialComManager classes: s
 
<!--  <dependency>
<groupId>org.bidib.com.serialpundit</groupId>
<artifactId>sp-tty</artifactId>
        <version>1.0.4.1</version>
</dependency>-->

rishi gupta

unread,
Aug 31, 2017, 9:25:40 PM8/31/17
to rucko24, SerialPundit
Please do not use any jar from maven. They are very old version and not updated. Please use only form github.

--
You received this message because you are subscribed to the Google Groups "SerialPundit" group.
To unsubscribe from this group and stop receiving emails from it, send an email to SerialPundit+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/SerialPundit/6c54cd64-4400-4e88-bf96-1ab969215c05%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages