Page 1 of 1

Could not initialize class gnu.io.CommPortIdentifier on tomc

Posted: Fri Mar 06, 2015 4:03 am
by mgoes
Hello,
I have Java installed by

sudo apt-get install oracle-java8-jdk

and rxtx installed by

sudo apt-get install librxtx-java

When I execute as a standard application, like this:

java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar:. -jar myApp.jar

it works without errors. But when I try to execute as a web application, a get the error mentioned in the title. That web application is working fine on OSX.I just created the war file and dropped it on raspberry's Tomcat webapps folder.

A strange thing is that, if I dont run the standard application before, I says "no rxtxSerial in java.library.path", instead what I mentioned before.

Re: Could not initialize class gnu.io.CommPortIdentifier on

Posted: Fri Mar 06, 2015 4:54 pm
by precious_pony
It is likely that you have to add the additional java library path the web application server (e.g. jetty or tomcat ).

For Jetty

Edit either :

/etc/default/jetty
or
/etc/init.d/jetty

and you are looking at the JAVA_OPTIONS section.

For Tomcat:

This answer on stack overflow might help.

Re: Could not initialize class gnu.io.CommPortIdentifier on

Posted: Fri Mar 06, 2015 5:14 pm
by mgoes
I have already seem that post on stack overflow. It didn't worked for me.
I tried to change from oracles's jdk to openjdk-7. But now I get "Unsupported major.minor version 52". It was compiled on jdk8. So I know the reason for that is the version of the compiler. Is openjdk-8 is available for raspbian?

Re: Could not initialize class gnu.io.CommPortIdentifier on

Posted: Fri Mar 06, 2015 11:45 pm
by mgoes
I did some modifications on my server, now I getting this message:

org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 41

38: <form name="Name Input Form" action="controlServlet" method="POST">
39: <label>Selecione a porta serial:</label>
40: <%
41: Enumeration pList = CommPortIdentifier.getPortIdentifiers();
42: ArrayList<String> p = new ArrayList<>();
43:
44: // Process the list.

I thought it could be caused by unresolved dependencies. The CommPortIdentifier class is located in RXTXcomm.jar, so I went to /usr/share/java/lib, copied RXTXcomm.jar and paste in [tomcat home]/webapps/myApp/WEB-INF/lib. It didn't work, its just the same.

Anybody knows what to do next?

Re: Could not initialize class gnu.io.CommPortIdentifier on

Posted: Sat Mar 07, 2015 9:58 am
by DougieLawson

Re: Could not initialize class gnu.io.CommPortIdentifier on

Posted: Sat Mar 07, 2015 10:37 pm
by mgoes
I installed RXTX by

Code: Select all

sudo apt-get install librxtx-java
. Ins't it enough?

Re: Could not initialize class gnu.io.CommPortIdentifier on

Posted: Sun Mar 08, 2015 8:28 am
by bullen
-cp and -jar don't work well together.

Try: java -Djava.library.path=/usr/lib/jni -cp /usr/share/java/RXTXcomm.jar:myApp.jar path.to.the.main.Class

Also if you wan't HTTP hot-deploy take a look at this.

Re: Could not initialize class gnu.io.CommPortIdentifier on

Posted: Mon Mar 09, 2015 3:19 am
by knute
The -cp option is ignored if -jar is specified.

Code: Select all

-jar filename

    Executes a program encapsulated in a JAR file. The filename argument is the name of a JAR file with a manifest that contains a line in the form Main-Class:classname that defines the class with the public static void main(String[] args) method that serves as your application's starting point.

    When you use the -jar option, the specified JAR file is the source of all user classes, and other class path settings are ignored.