Textpad: Java cannot run with package

631 Views Asked by At

I tried to compile and run Java 10 file with TextPad, it works nicely until I decide to put the file in a folder and use Package(namespace). It seems to be unable to load classes, I get this error:

Error: Could not find or load main class com.MyProject.HelloWorld
Caused by: java.lang.ClassNotFoundException: com.MyProject.HelloWorld

Is there anything I can do about this? I dont seem to find how it is possible to define the class path in TextPad, so I am stuck.

2

There are 2 best solutions below

0
On

You need to compile it like this:

>javac ./com/MyProject/HelloWorld
2
On

After the compiling... From the console, try to specify the java HOME, then the path, then the module and the main class: For example:

"C:\Program Files\Java\jdk-10\bin\java.exe" -p C:\Users\User\MyFolder -m com.mymodule/com.MyProject.HelloWorld