I have a JAR file, which has many dependencies (ApacheCommons stuff mostly). When I put all those JAR's in the same directory as my main JAR, everything works fine. But that makes a mess and it also means that people have to carry all those external libraries around whenever they move my program's JAR on their system.

So I put them all in a separate directory and added that directory's path to CLASSPATH environment variable (using /etc/environment). Now even though echo $CLASSPATH returns that path, still running my JAR without those libraries in the same directory causes java.lang.NoClassDefFoundError (which happens when it can't find external JARs needed).

Any help/ideas would be highly appreciated.


This is not really a ubuntu-Problem, see this question on stackoverflow.

The CLASSPATH-Variable does not list pathes to jar-files, but pathes to Java-class-files. To include a jav-file in a classpath you have to put jar-file filename in the classpath (e.g. CLASSPATH=/path/to/some/jar/file/jarfile.jar).

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.