Java cmd configuration (that is, Java JDK configuration and related common commands)-solution for failing to find or loading the main class, cmdjdk

Source: Internet
Author: User

Java cmd configuration (that is, Java JDK configuration and related common commands)-solution for failing to find or loading the main class, cmdjdk

Java cmd configuration (that is, Java JDK configuration and related common commands)

-- Solution that cannot be found or cannot load the main class

This period of time has been entangled in the problem that Java cannot be compiled and run under cmd. The main problems are described as follows:

The javac command can run normally, while the java command can run normally sometimes, but sometimes it is not. The symptom of failure is that "the main class cannot be found or loaded ".

 

I found a variety of materials on the Internet and found that the Code contains package statements, so I cannot run java commands in cmd to explain the. class file. The package statement is not used for files that can be run.

The solution to this problem is to use several special commands.

Common commands are:

// The comment here uses "//". to copy the code to cmd, do not copy the comment.
// Set. java file name to filename // note that the main class name and file name are identical, including case sensitivity.
Javac filename. javajava filename

If the Code contains a package statement, you must use

The directory filename. java specified by javac-d // such as javac-d F: filename. java

After execution, a folder is generated in the specified directory. If the specified directory is ".", it indicates the current directory. The folder name is the package name (set to pkname ).

java pkname.filename  

To run.

If the program uses multiple. java files or multiple. class files, you can also use these two statements.

Link: http://blog.sina.com.cn/s/blog_673bf2100100hrgd.html

 

 

 

Other frequently asked questions:

1. The javac and java versions are different:

Enter

Java-version // display the java command version

And

Javac-version // display the version number of the javac command

If the java version is later than the javac version, java can still run normally. However, if the java version is earlier than javac, java cannot run normally. The lower version of java cannot run the. class file compiled by the later version of javac.

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

If the URL is invalid, Baidu "java and javac"

2. environment variable settings:

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

In general, if you set the system, all users can use it. If you set the user, the current user can use it. If you change the user, it will be difficult. But most people in Windows do not have this problem, so both of them can. If you are not sure, set the system. If you don't feel at ease, set them both (for example, me ..).

Set JAVA_HOME first.

// JAVA_HOMED: \ Java \ jdk1.8.0 _ 05/* Note whether D: \ Java \ jdk1.8.0 _ 05 or D: \ Java \ jdk1.8.0 _ 05 \, the difference between the two is "\" */

Then the PATH

// PATH // Add.; % JAVA_HOME % \ bin at the beginning of the original PATH value;/* Note that the current directory starts. Here, % JAVA_HOME % is equivalent to the string you assigned to it, so if your % JAVA_HOME % contains, the content added by your PATH should be .; % JAVA_HOME % bin ;*/

Then the CLASSPATH

// CLASSPATH .; % JAVA_HOME % \ lib \ tools. jar; % JAVA_HOME % \ lib \ dt. jar; % JAVA_HOME % \ lib;/* here, ", indicating the current directory, so that you can enter a directory for cd and execute. java file. The "\" in front of lib is not added, which is the same as the PATH processing method. */

With a URL: http://blog.163.com/zhouru729@126/blog/static/82764270200711423542180/

 

22:23:09

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.