Skip to content

Tag: classpath

How to set the classpath correctly in java

I need to compile and run simple code using the gson library, but I can’t use Maven, Gradle or the IDE. The directory contains and gson-2.9.0.jar javac -cp gson-2.9.0.jar works correctly and creates Main.class But when I run java -cp ./*: Main, I get I also tried the following commands: But all these commands give the same result.

How to run a java class with a jar in the classpath?

So, I can do this very well: if ./mypackage/MyClass.class exists. I can also happily do this: if the class file exists in the appropriate part of the jar. Easy stuff. But I can’t for the life of me manage to do something like this: where ./mypackage/MyClass.class exists, and where ./utilities.jar exists (not containing MyClass, of course). Am I about to