Discover problems
After switching to the Mac platform, suddenly want to write a program run under the Mac, think of the Mac comes with Java, will be much easier. But in the process of encountering trouble:
Always prompt for "error: The main class could not be found or could not be loaded "
Engineering structure
Looked for a long time, finally found the prototype, found on the internet a lot of information is not too much to write their own record. First look at the location and directory of the project.
My Eclipse Workspace location is: /users/zhangyunfei/Workspace_java
my project name is called: Hellodemo
my main class's package name is: HELLODEMO.ZHANGYF, the full class name is: Hellodemo.zhangyf.MainClass
so the main path of the project is: /users/zhangyunfei/workspace_java/hellodemo, the structure is as follows:
Hellodemo
Bin
Hellodemo
Zhangyf
Mainclass.class
Src
Hellodemo
Zhangyf
Mainclass.java
Where bin is the eclipse auto-generated output file, eclipse will edit the Java file into a *.class file. This *.class file is available for operation.
Relative path Execution mode
Cd/users/zhangyunfei/workspace_java/hellodemo
JAVA-CP bin Hellodemo.zhangyf.MainClass
Note: This is followed by the path to the project, which is then executed using the relative path bin.
Absolute path Execution mode
In my project structure, the command to execute this class is that you can execute it in Bash (Command Prompt window) by entering the following instruction:
Java-cp/users/zhangyunfei/workspace_java/hellodemo/bin Hellodemo.zhangyf.MainClass
Java is the execution of Java class execution instructions,-CP represents the class path, that is, the path of the class, followed by the actual path, note that the "class is the same path", that is, the path of the bin directory. Then follow the full name of class.
Thank
Reference: http://bbs.csdn.net/topics/390813742
Use Java to run a class file under Mac always prompt "error: cannot find or Load main class" workaround