Java – cannot run jar files on another PC Possible problems with environment variables?
I have built a jar file that performs well on my PC (XP) with eclipse installed It also applies to another PC that also has eclipse
I tried running it on another PC (XP) without eclipse Although it contains JDK and multiple jres Execute the jar file by clicking or from the command prompt
I'm not quite sure, but my best guess is that the environment variable is set incorrectly This is the error I received from the command prompt:
Exception in thread "main" java.lang.NoClassDefFoundError: ...
Any help will be greatly appreciated
Solution
This may be what others call a classpath problem
One thing to note is how your jar is constructed There are many options in the dialog box for exporting runnable jars;
>Extract classes into jar > compress dependencies into jar – create jar in jar loader jar. > Place the jar in a subdirectory next to the jar
It depends on what you choose for this and how the jar behaves If the class is extracted, the dependent class not in the JDK should be on the classpath I suggest this method because it is simpler
Now, the question is – do you use dependencies in the classpath instead of in the build dependencies of your eclipse project? If so, it will not be packaged / compressed next to jar because eclipse does not know it (but Java will still find it on your system because it is on the classpath) In addition, if you have saved an ant script and updated the build path in eclipse, eclipse will not update the ant script that is generated only once