Java's cmd configuration (also known as Java's JDK configuration and associated common commands)--The workaround for the main class cannot be found or loaded

Source: Internet
Author: User

Java's cmd configuration (also known as Java's JDK configuration and related common commands)

--The workaround for the main class could not be found or could not be loaded

This period of time has been entangled in the CMD under the Java cannot compile the problem of running. The main issues are described below:

The Javac command runs normally, and Java commands sometimes work, sometimes not, and the symptom is "the main class cannot be found or cannot be loaded".

Found all kinds of information on the Internet, the final discovery is because the code contains the package statement, so you cannot run the Java command under CMD to interpret the. class file. And the files that can be run are because the package statement is not used.

My solution to this problem is to use a few special commands.

The common commands are Javac file.javaname and J Ava FileName (the. java file name is filename), and here's a note that the name and file name of the main class are identical, including case.

If there is a package statement in the code, the directory Filename.java (such as javac-d F:filename.java) specified by javac-d is used, and then a folder is generated in the specified directory, and if the specified directory is ".", the current directory is represented. The folder name is the name of the package (set to Pkname), then the CD enters the folder and runs with Java Pkname.filename.

Special Inspirational URL One: http://blog.sina.com.cn/s/blog_673bf2100100hrgd.html

Other FAQs:

1.javac and Java versions are different:

Enter java-version and javac-version under CMD to display the version number of the two commands, respectively. If the version number of Java is higher than the version number of Javac, Java will still work. However, Java does not work correctly if the version number of Java is lower than Javac. Because the lower version of Java cannot run the. class file that was compiled by the higher version of Javac.

Workaround attached URL: http://blog.csdn.net/feihong247/article/details/7878873

If the URL is invalid, Baidu "Java and Javac version"

2. Environment variable Setting problem:

First explain the environment variables should be set user or system, with URL: http://www.blogjava.net/tyjava/articles/390788.html

In general, the system is set up by all users can use, set the user's current user can use, change user is not good to make. But most people don't have this problem on windows, so two of them are fine. If you're not sure, set up the system. Do not rest assured that the two are set up (such as me. )。

First set up Java_home, my is D:\Java\jdk1.8.0_05 (note here is D:\Java\jdk1.8.0_05 or D:\Java\jdk1.8.0_05\, the difference between a "\")

And then path, I added the original path value at the front.;    %java_home%\bin; (Note that the "." Begins with the current directory. And here the%java_home% is equivalent to the above you assign value to the string, so if your%java_home% is with "\", your path to add the content should be.; %java_home%bin; )

And then the Classpath, mine is.    %java_home%\lib\tools.jar;%java_home%\lib\dt.jar;%java_home%\lib; (the "." is still here.) Start with the current directory so that you can enter a directory and execute the. java file under that directory. As for the "\" in front of the LIB, the same path as the method of processing. )

2015-05-28

22:23:09

Java's cmd configuration (also known as Java's JDK configuration and associated common commands)--The workaround for the main class cannot be found or loaded

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.