0

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?

halloleo
  • 9,216
  • 13
  • 64
  • 122
  • This thread may help you to figure out the solution: https://stackoverflow.com/questions/9395207/how-to-include-jar-files-with-java-file-and-compile-in-command-prompt – patrinox Sep 13 '22 at 09:08
  • @patrinox Thanks. This got me to the solution: I forgot that the JAR _itself_ needs to be in the `CLASSPATH` property, not only the _directory_ containing the JAR. – halloleo Sep 14 '22 at 00:49

1 Answers1

0

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
halloleo
  • 9,216
  • 13
  • 64
  • 122