I have a small application that depends on a couple of JAR files provided by the Apache Commons folks. In my IDE, I just add those JAR files to the classpath (or I've also verified that I can do so at the command line). However, I need to run this application on a machine that I'm not developing on, and even though I've matched drive letters and directory paths, etc, I'm still having problems at the command line:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/httpclient/HttpException
All I have are two class files and then the two Apache Commons JAR files, and on both machines I have all of these 4 files in the same directory. As far as I can tell, the classpath matters only for javac (compilation), and doesn't affect anything when running an app.
The best thing would be to just compile it on the other machine, but it only has the JRE at the moment, and I can't restart it to fully install the compiler just anytime I want since it's a server that needs to stay up most of the time.
So, I've been trying to create a JAR files that hopefully would just contain EVERYTHING the app would need. I've tried to figure out how to compile the JAR so that it includes those other JAR files and the classes know to look in those included JAR files for the packages they need, but I don't know how to do this. I've wondered if you can somehow set the classpath for creating a JAR file (like on the command line when you're actually creating the JAR), but I haven't found anything like that online.
Please give me your best shot for getting this thing running...
Of course you need to include required classes in the classpatch for running the app also. If all files are in the same directory, make sure to explicitly include each jar file in the classpath. As well as the current directory "."
i.e. $JAVA_HOME/bin/java - classpath .;jar1.jar;jar2.jar MyClass
If you have packaged your own classes in a jar file, you will need to include each external jar in the class-path property in the manifest file.