When I try running my Java application, it cannot find the main class in the directory I specify.

My application is in this directory:

C:\Users\Cristian\git\tranquil-crag-4851

My main class is in this directory:

C:\Users\Cristian\git\tranquil-crag-4851\target\classes\com\example

My main class is called

Main.class

When I run this command

java -cp target/classes:target/dependency/* com.example.Main

from directory

C:\Users\Cristian\git\tranquil-crag-4851\

the result I get is:

Could not find the main class in com.example.Main

My CLASSPATH variable is set to JAVA_HOME\lib. Can somebody explain to me how to solve this?

3

1 Answer

The delimiter : works on Unix. You should use ; on Windows instead. I am not sure that forward slashes work on Windows in this context. Try to use back slashes instead, i.e.

java -cp target\classes;target\dependency\* com.example.Main

If you are using java 1.6 or higher this should work. I mean that * was not supported by previous versions of java.

If something does not work, check the path. Go to the directory where you are running your application, type

dir target\classes dir target\dependency\ 

and see that the output of these commands is as expected.

1

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.