i have the following project structure:
JavaTest
Main
Main.java
Test
Test.java
Main.java:
package Main;
import Test.*;
public class Main {
public static void main(String[] args) {
}
}
Test.java:
package Test;
public class Test {
}
I compile them with the following commands:
D:\Development\Workspace\JavaTest>javac Main\Main.java
D:\Development\Workspace\JavaTest>javac Test\Test.java
The class files are put like this:
JavaTest
Main
Main.java
Main.class
Test
Test.java
Test.class
I'm trying to run it with the following command:
D:\Development\Workspace\JavaTest>java -cp D:\Development\Workspace\JavaTest\Main;D:\Development\Workspace\JavaTest\Test Main
The error i'm getting is:
Error: Could not find or load main class Main
Caused by: java.lang.NoClassDefFoundError: Main/Main (wrong name: Main)
add the package to your main class and set the classpath to the base directory
D:\Development\Workspace\JavaTest>java -cp D:\Development\Workspace\JavaTest Main.Main
I'd recommend you stick to Java conventions and use only lowercase names in your package. And you don't need the Test path to run your class
Do it as follows:
javac -d . Main/Main.java
java Main.Main
Notes:
.
main
. Check https://www.oracle.com/technetwork/java/codeconventions-135099.html for more details.javac -help
to know more about the options available with javac
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.