• 0

[Help] Compile and running a java which uses libraries in linux


Question

I have a java program which has all it's *.java files in the src directory. it uses libraries (e.g. activemq-core-5.1.0.1.jar and commons-logging.jar) stored in a folder called libs which is in the directory level as the src folder.

how do i compile this program in linux and convert it to a jar file?

once compiled how do i do run it? will simply running the jar file i just created be sufficient?

Link to comment
Share on other sites

15 answers to this question

Recommended Posts

  • 0

thanks.. when i run the jar file i created will i have to specify the classpath then too?

when i just try running it i get the following

[ruzaik@localhost src]$ java -jar TestTx.jar 
Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/Destination
Caused by: java.lang.ClassNotFoundException: javax.jms.Destination
		at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
		at java.security.AccessController.doPrivileged(Native Method)
		at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
		at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
		at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
		at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
		at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

btw the jar i created (i.e. TestTx.jar) is not in the same directory as the libraries (i.e. commons-logging.jar, activemq-core-5.1.0.1.jar).. the libraries are in a libs folder which is in the same directory level as the src folder.. the jar file i created is in the src folder...

Link to comment
Share on other sites

  • 0

i tried running the jar using the following:

java -jar TestTx.jar -cp ../libs/commons-logging.jar:../libs/commons-logging-api.jar:../libs/geronimo-jms_1.1_spec-1.0.jar:../libs/geronimo-j2ee-management_1.0_spec-1.0.jar:../libs/activemq-core-5.1.0.1-fuse.jar:../libs/mrecharge-component-integration-1.13.jar

but i get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/jms/Destination
Caused by: java.lang.ClassNotFoundException: javax.jms.Destination
		at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
		at java.security.AccessController.doPrivileged(Native Method)
		at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
		at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
		at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
		at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
		at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

any ideas as to why?

Link to comment
Share on other sites

  • 0

OK. I may be heading down completely the wrong path here... but since nobody else seems to have a better idea...

The exception is caused by the class loader not being a able to find javax/jms/Destination. I've tested my Windows 1.6u11 SE installation, and I can't find the javax.jms package there, which is consistent with the javadoc that says its part of JavaEE.

Are you able to do a quick manual search and find where the package is installed on your system? Wherever it is, that's the library that's not being found properly. Feel free to ignore this if you think it's a blind alley. James

Link to comment
Share on other sites

  • 0

Sorry man, I don't know. It's just that the exception says it can't find that class/package, so that seems like a good place to start. Anyway, good luck & Merry Xmas. J

Link to comment
Share on other sites

  • 0

Further thoughts...

You're apparently using the jms classes from the Geronimo libraries, which is why it works without Java EE.

In which case, the problem lies in the classpath for geronimo-jms_1.1_spec-1.0.jar.

It might be interesting to try putting those library jars in the JRE lib/ext directory and leaving the classpath at its default value, which should help confirm the problem diagnosis.

Link to comment
Share on other sites

  • 0
It might be interesting to try putting those library jars in the JRE lib/ext directory and leaving the classpath at its default value, which should help confirm the problem diagnosis.

i'm sorry i didn't understand this bit :(

Link to comment
Share on other sites

  • 0

The JRE will (should?) find jars you put in its lib/ext folder without any special classpathing. So if that works it means there was something wrong with the -cp when you run your jar. If it doesn't work then there's probably something wrong in the jar itself.

Link to comment
Share on other sites

  • 0

hey i managed to find a solution to this with some help.. for those interested.. the classpath should be defined in the manifest file as the Class-Path property and each library should be separated by a space instead of a ";" or ":".. nevertheless thanks James for your efforts.. appreciate it :)

Edited by rustix
Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.