I am trying to compile and run from the command line a simple java hello world program.
It compiles and runs successfully when I do:
> javac HelloWorld.java
> java HelloWorld
However, when I place a jar-dependency in this hello world program and the corresponding jar in the same directory, I run into a classpath issue.
I can compile with:
> javac -cp ./* HelloWorld.java
But I when I attempt to run while specifying the classpath to the jar, my HelloWorld class is not found.
> java -cp ./* HelloWorld
Error: Could not find or load main class HelloWorld
When classpath is ./*
, the jar is found but not the class, and when classpath is .
, the class is found but not the jar.
I also tried specifying both, but the main class is not found whenever I use a :
in the classpath.
> java -cp "./*:." HelloWorld
Error: Could not find or load main class HelloWorld
How can I specify classpath for java to find both the jar and my class?