Java: Exception in thread "main" java.lang.NoClassDefFoundError

To compile my java application, I use from a terminal:

javac -cp commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar CollectionIndexer.java

To run the application, I use:

java -classpath commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar CollectionIndexer

However, I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: commons-digester-2/1/commons-digester-2/1/jar:lucene-core-3/0/3/jar
Caused by: java.lang.ClassNotFoundException: commons-digester-2.1.commons-digester-2.1.jar:lucene-core-3.0.3.jar
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)

I assume that I am defining the classpath correctly .. or what?

+3
source share
2 answers

Try -cpinstead classpath. Also add the current directory to the classpath.

$ java -cp .:commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar CollectionIndexer

or

$ export CLASSPATH=.:commons-digester-2.1/commons-digester-2.1.jar:lucene-core-3.0.3.jar
$ java CollectionIndexer

If on Windows, use a backslash and a comma separator:

java -cp .;commons-digester-2.1\commons-digester-2.1.jar;lucene-core-3.0.3.jar CollectionIndexer
+1
source

I suggest you first set the classpath with

Install the CLASSPATH command, and then run your program as

java CollectionIndexer.

0
source

Source: https://habr.com/ru/post/1794379/


All Articles