0

I've just istalled JDK8 on PC Windows 11 Home Now im trying to run simple default program from NetBeans14

In environmental variables:

PATH : C:\Program Files\Java\jdk1.8.0_202\bin

CLASSPATH : C:\Program Files\Java\jdk1.8.0_202\bin

Project build on hard disk C:\Projects\Hello\src\main\java\pack\hello

  1. on cmd going tn cd C:\Projects\Hello\src\main\java\pack\hello

  2. javac compiles .java file on .class file

  3. command "java Hello" output: Error: Could not find or load main class Hello Hello.class is there.

checking commands, all works:

java

javac

javac -version

Please to support, or send some similar problems posts. All web answers are speaking about setting PATH and CLASSPATH, where in my case it already took place.

Thanks in Advance

  • 2
    “CLASSPATH : C:\Program Files\Java\jdk1.8.0_202\bin” is incorrect. The classpath a series of locations where Java programs exist. It should *never* point to a location inside a Java installation. You probably want to set CLASSPATH to `C:\Projects\Hello\target\classes`, if your project is a Maven project. – VGR Jul 18 '22 at 03:04
  • I think you would face this issue due to not considering the package in **compilation** or in **execution** Follow this Link : https://stackoverflow.com/questions/1279542/how-to-execute-a-java-class-from-the-command-line – Jimmy Jul 18 '22 at 11:44
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Jul 18 '22 at 13:07
  • CLASSPATH changing on directory with class -not working considering package running using "java" - not working – Bartek Czerwiński Jul 18 '22 at 16:26

1 Answers1

0

I tried to follow your steps. I downloaded and installed the newest JDK 8 on Windows 11, and NetBeans 14.

Then I looked through the Environment Variables, and the only mention of Java was in the system Path variable:

enter image description here

You see, I have no CLASSPATH variable, nor haven't I manually set anything. Everything was installed automatically. I have no explicit path to C:\Program Files\Java\jdk1.8.0_... in my Path variable.

And I created a simple app in NetBeans. It runs from NetBeans successfully. Just do "Run Project" (F6) in the NetBeans interface.

If you need to run it from the command line for some reason, this question may help.

If you need to run it on another computer, I would advise you not to do it with cmd. Compile it into jar, then wrap it into exe (in case of Windows) using launch4J.

HoRn
  • 1,458
  • 5
  • 20
  • 25