0

When I use the java/javac command on cmd as in

javac Theory/HelloWorld.java java Theory.HelloWorld

it works just fine, yet when I do that on the VSCode terminal it doesn't work at all and says "Error: Could not find or load main class Theory.HelloWorld. Caused by: java.lang.ClassNotFoundException: Theory.HelloWorld"

Running the code with the Run Java button works just fine, it's just when I want to add arguments Any ideas?

PS: Using the java -cp . Theory/HelloWorld works fine, it's just that it becomes a mess when I try to use that command when the main class uses different classes

I've tried set CLASSPATH=. Clean Java Language Server Workspace Used different terminals Configured Classpath in VSCode with the "." path

7
  • 1
    it's just that it becomes a mess when I try to use that command when the main class uses different classes How so? Please give an example. Commented Aug 12, 2023 at 19:05
  • "it becomes a mess when I try to use that command when the main class uses different classes", why? You don't need to put every class on the classpath, just the root directory or jar(s) or some such. Commented Aug 12, 2023 at 19:06
  • When the main class is using different classes in the same package, if I want to run the command javac [location].java it says that it cannot find symbol [Class name] Commented Aug 12, 2023 at 19:46
  • Just try javac -cp . Theory/*.java Commented Aug 12, 2023 at 19:56
  • is the cwd the same in both cases you are comparing? Commented Aug 13, 2023 at 21:51

0

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.