user1563426
user1563426

Reputation: 21

Can not find or load main class from cmd when using absolute paths

I can not run my Java class from the command prompt using absolute paths.

In the cmd, when I CD to C:\Automation\XML_wrapper\bin and type java wrapper it works.

When I at in C:\ and type C:\program files\java\jdk.xxx\bin\java C:\Automation\XML_wrapper\bin\wrapper it does not work.

I tried variants of the java command, including quotes and including .exe.

I also tried variants of the java class including adding -cp C:\Automation\XML_Wrapper\bin and including .class at the end.

Upvotes: 2

Views: 1944

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1500575

You need to pass a class name to java - not a file name. You'll also probably need to provide a class path to say where to find the file:

java -cp C:\Automation\XML_wrapper\bin wrapper 

The -cp argument just tells the JVM where to load classes from - it can be a sequence of directories and/or jar files. The wrapper part is the name of the class, which is more commonly something like com.acme.SomeApplication - that's class SomeApplication within the com.acme package. (A class name of just wrapper would break Java naming conventions. It's not illegal, just unconventional.)

Upvotes: 1

Related Questions