0

I want to be able to execute a java class from Command Prompt in windows without specifying the classpath explicitly every time I want to execute a java class, for example like this

where I execute the HelloWorld class in the "ExamplePackage" package.

I want to accomplish the same result without specifying the classpath, as follows

enter image description here

but this gives me an Error: Could not find or load main class HelloWorld. As I understand it, this error is caused by java not being able to locate the class since classpath has not been specified.

Now, I want to solve this problem by setting a global variable classpath value to C:\Users\UpdatusUser\Desktop\ExampleProject.

This can be accomplished, as I understand, over here

enter image description here

But that does not seem to solve the issue, since I still get the following result if I now use java ExamplePackage.HelloWorld

enter image description here


What am I doing wrong?

1 Answers1

1

For a full explanation see this:

What does "Could not find or load main class" mean?

The short answer is execute the java command from the ExampleProject folder not the ExamplePackage folder.

Community
  • 1
  • 1
Centinul
  • 874
  • 3
  • 10
  • 18