jQuery in Action, 3rd edition
The moose likes Beginning Java and the fly likes Loading jar files for a .class file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Loading jar files for a .class file" Watch "Loading jar files for a .class file" New topic

Loading jar files for a .class file

Arno Pronk

Joined: Apr 20, 2009
Posts: 3
I have a problem with a program that i wrote called chat. I need to run it in a command box with the command "java chat". However it needs a few extra jar files to run. Is there anyway i can use a parameter (like -classpath) to load the following jar files with the program i wrote?

Regards, Arno
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46349
Welcome to JavaRanch.

If you look in the documentation for the java tool, you will find the -classpath (or -cp) option, which might provide what you need.
Arno Pronk

Joined: Apr 20, 2009
Posts: 3
Hi, thanks for the reply

I still cant get it to work, so i would appreciate some more help.

It try to run it now with the command:

java -classpath /home/arno/jboss-4.2.3.GA/server/default/lib/:/home/arno/jboss-4.2.3.GA/lib/:/home/arno/workspace/5SimpleChatServer/bin/ Chat

Is this the right use of claspath?

The error that I keep getting is:
:~/workspace/5SimpleChatServer/bin$ java -classpath /home/arno/jboss-4.2.3.GA/server/default/lib/:/home/arno/jboss-4.2.3.GA/lib/:/home/arno/workspace/5SimpleChatServer/bin/ Chat
Exception in thread "main" java.lang.NoClassDefFoundError: Chat
at java.lang.Class.initializeClass(libgcj.so.90)
Caused by: java.lang.ClassNotFoundException: javax.jms.JMSException not found in gnu.gcj.runtime.SystemClassLoader{urls=[file:/home/arno/jboss-4.2.3.GA/server/default/lib/,file:/home/arno/jboss-4.2.3.GA/lib/,file:/home/arno/workspace/5SimpleChatServer/bin/], parent=gnu.gcj.runtime.ExtensionClassLoader{urls=[], parent=null}}
at java.net.URLClassLoader.findClass(libgcj.so.90)
at gnu.gcj.runtime.SystemClassLoader.findClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.ClassLoader.loadClass(libgcj.so.90)
at java.lang.Class.forName(libgcj.so.90)
at java.lang.Class.initializeClass(libgcj.so.90)

Joanne Neal

Joined: Aug 05, 2005
Posts: 3742
If you follow the 'Setting the Class path' link in the page that Campbell linked to you will find this
For a .jar or .zip file that contains .class files, the class path ends with the name of the .zip or .jar file.

Arno Pronk

Joined: Apr 20, 2009
Posts: 3
Thanks! I got it working now.
I agree. Here's the link: http://aspose.com/file-tools
subject: Loading jar files for a .class file
It's not a secret anymore!