I have a folder libs
that contains several JARs, and I have an application (let's say MyTest.jar
) that uses some classes from those libs. What I need is to run MyTest.jar
with a kind of -cp
(-classpath
) argument that will add all JARs in folder libs
to classpath fully.
I have already tried java -cp E:\libs -jar MyTest.jar
. However, this doesn't seem to load the libraries at all, as can be seen in this error I get (which states it can't find one of library classes me.darksidecode.simpleconfigs.Config
):
Exception in thread "main" java.lang.NoClassDefFoundError: me/darksidecode/simpleconfigs/Config
at me.darksidecode.KekGUI.<init>(KekGUI.java:31)
at me.darksidecode.KekGUI.main(KekGUI.java:63)
Caused by: java.lang.ClassNotFoundException: me.darksidecode.simpleconfigs.Config
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
The line where the exception is thrown is:
Config testcfg = new Config("hello = world");
Where Config
(me.darksidecode.simpleconfigs.Config
) is a class of the SimpleConfigs.jar
library, which is present in my libs
(E:\libs
) folder and is valid.
To no avail I have also tried specifying one of libraries (SimpleConfigs.jar
) explicitly: java -cp E:\libs\SimpleConfigs.jar -jar MyTest.jar
. Same error happens.
How can I get this to work?
EDIT: it appears that I have to specify classpath in the MyTest.jar
's MANIFEST.MF file. And here I've got a new problem: I can only specify exact JAR name in Class-Path
, like this:
Class-Path: /E:/libs/SimpleConfigs.jar
It works like that. But when I try to specify the whole directory:
Class-Path: /E:/libs/
It starts throwing the aforementioned error (java.lang.NoClassDefFoundError
) again.