Use Java to run a class file under Mac always prompt "error: cannot find or Load main class" workaround

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.