Failed to execute compiled .classes from command line

I'm having some problems running my compiled Java code from the command line. I wrote this and compiled it using the IntelliJ IDE (where everything works fine if done in the IDE), but now you want to run it from the command line.

Compiling from the like command (using javac) also works fine, but it works (with java).

I am pretty sure this is a classpath issue, but cannot fix it. From my search before publishing this message, I found a message telling me to run the set command PATH = \% PATH \%; "C: \ Program Files \ Java \ jdk1.6.0_21 \ bin" and then try to run java. also tried various arguments i found for -cp and -classpath. Error:

Exception in thread "main" java.lang.NoClassDefFoundError: Share/class
Caused by: java.lang.ClassNotFoundException: Share.class
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: Share.class.  Program will exit.
+3
1

:

java -cp ... Share.class

Do

java -cp ... Share

java -cp ... path.to.Share

, .

(),

java -cp . Share

java Share

java, /jar, ( ).

.

+8

Source: https://habr.com/ru/post/1778977/


All Articles