mgoes
Posts: 4
Joined: Fri Mar 06, 2015 3:51 am

Could not initialize class gnu.io.CommPortIdentifier on tomc

Fri Mar 06, 2015 4:03 am

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.

precious_pony
Posts: 34
Joined: Tue May 22, 2012 11:09 pm

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

Fri Mar 06, 2015 4:54 pm

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.

mgoes
Posts: 4
Joined: Fri Mar 06, 2015 3:51 am

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

Fri Mar 06, 2015 5:14 pm

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?

mgoes
Posts: 4
Joined: Fri Mar 06, 2015 3:51 am

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

Fri Mar 06, 2015 11:45 pm

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?

User avatar
DougieLawson
Posts: 36578
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

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

Sat Mar 07, 2015 9:58 am

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

mgoes
Posts: 4
Joined: Fri Mar 06, 2015 3:51 am

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

Sat Mar 07, 2015 10:37 pm

I installed RXTX by

Code: Select all

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

bullen
Posts: 283
Joined: Sun Apr 28, 2013 2:52 pm

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

Sun Mar 08, 2015 8:28 am

-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.
https://github.com/tinspin/rupy - A tiny Java async HTTP application server.

knute
Posts: 477
Joined: Thu Oct 23, 2014 12:14 am
Location: Texas
Contact: Website

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

Mon Mar 09, 2015 3:19 am

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.

Return to “Java”