halloleo
halloleo

Reputation: 10354

How do I get a JAR file in the current directory in the class path for a Java execution?

I have a class file Main.class which needs a JAR file abc.jar to run.

Both files are in the same directory. Now I try to run the class file with

java -cp "." Main

but I get a java.lang/NoClassDefFoundError.

I thought -cp "." tells the classpath to include the current directory, but somehow it doesn't.

How do I get this JAR file in the current directory on the class path?

Upvotes: 0

Views: 400

Answers (1)

halloleo
halloleo

Reputation: 10354

Thanks to patrinox' comment I figured it out:

The JAR itself needs to be in the CLASSPATH property, not only the directory containing the JAR. Therefore the command line has to read:

java -cp ".:./abc.jar" Main

Upvotes: 0

Related Questions