A detailed description of the. classpath file in the Eclipse project

Source: Internet
Author: User

1 Preface

When using eclipse or MyEclipse for Java project Development, there is a. classpath file under each project, so what does this file do?

1 use

The. classpath file is used to record all information about the project's compilation environment, including the source file path, the compiled class file storage path, the dependent jar package path, the container information that is running, the dependent external project, and so on. If the file is deleted, eclipse cannot say that the project is recognized as a normal Java project and is not functioning as a normal folder.

3. Classpath Content

The. classpath file is also an XML-formatted content file with the following details:

<?xml version= "1.0" encoding= "UTF-8"?><Classpath><ClasspathentryKind="SRC"Path="src"/><ClasspathentryKind="SRC"Path="Resource"/><ClasspathentryKind="Con"Path="org.eclipse.jdt.launching.jre_container/org.eclipse.jdt.internal.debug.ui.launcher.standardvmtype/jdk1.7" ><Attributes><AttributeName="Owner.project.facets"Value="Java"/></Attributes></Classpathentry><ClasspathentryKind="Con"Path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimetarget/Learning 8080" ><Attributes><AttributeName="Owner.project.facets"Value="Jst.web"/></Attributes></classpathentry> <classpathentry Span class= "Hljs-attribute" >kind= "con" path=" Org.eclipse.jst.j2ee.internal.web.container "/> < classpathentry kind= "con" path= "Org.eclipse.jst.j2ee.internal.module.container"/> Span class= "Hljs-tag" ><classpathentry kind=" output "path=" webcontent/web-inf/classes "/ ></CLASSPATH>      
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19

① with "Classpath" as the root node, each "Classpathentry" node represents a descriptive message.
② each "Classpathentry" indicates the type with the "kind" attribute, and "path" indicates the path.
③ all content of the above file is changed by the "Java Build path" content in the project, that is, all operations on "Java build path" will be reflected in the file contents.

Now to specifically analyze the meaning of each node of the file content

3.1 kind="src"

SRC: That is, the source file, which represents a source file, path= "src" is a relative path, relative to the. classpath file itself, that is, path= "src" means that the folder Src is in the same directory as the. Classpath and represents the source file.

<classpathentry kind="src" path="src"/><classpathentry kind="src" path="resource"/>
    • 1
    • 2

kind= "src" action corresponds to "Source" tab page of "Java Build Path"

For example, adding a folder bin as the source file, the. classpath file adds content

The content is added as follows:

<classpathentry kind="src" path="src"/><classpathentry kind="src" path="bin"/><classpathentry kind="src" path="resource"/>
    • 1
    • 2
    • 3

Of course, do the corresponding modification or deletion, the same. classpath file contents will change accordingly.
In addition, when the specified attribute combineaccessrules= "False" is the representation of the introduction of external project, as follows

<classpathentry combineaccessrules="false" kind="src" path="/mybatis"/>
    • 1

The corresponding page tab, where Path= "/mybatis", is relative to workspace under the
Absolute path.

3.2 kind="output"

Output is used to specify the Java source file after the compiled class file storage path, in the following format

<classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
    • 1

Path: Represents the path of the class file, also relative to the path of the. classpath file, find "Webcontent/web-inf/classes", you can see the storage of the class file

If you modify the output file path, the corresponding content will also change
Instead: spring-mybatis\webcontent\web-inf\newclasses

The contents of the. classpath file are modified to:

<classpathentry kind="output" path="WebContent/WEB-INF/newclasses"/>
    • 1

The path that actually holds the class file will also change

3.3 kind="con"

Con is the container, is the program running container, or is said to be running environment OK, it is actually in MyEclipse initially to configure installed JREs in the specified (normally we specify the JDK), But what is actually used here is the jar package in the JRE under the JDK, that is, the jdk_home/jre/lib is the corresponding statement. Specific content is as follows

<ClasspathentryKind="Con"Path="org.eclipse.jdt.launching.jre_container/org.eclipse.jdt.internal.debug.ui.launcher.standardvmtype/jdk1.7" ><Attributes><AttributeName="Owner.project.facets"Value="Java"/></Attributes></Classpathentry><ClasspathentryKind="Con"Path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimetarget/Learning 8080" ><Attributes><attribute name=  "owner.project.facets" value= " Jst.web "/> </attributes> </< Span class= "Hljs-title" >classpathentry> <classpathentry Span class= "Hljs-attribute" >kind= "con" path=" Org.eclipse.jst.j2ee.internal.web.container "/> < classpathentry kind= "con" path= "Org.eclipse.jst.j2ee.internal.module.container"/>  
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12

The corresponding Action tab is as follows

3.3.1 JRE Configuration

Path= "XXX" is used to specify the usage of the JRE container, the different sources of the JRE can be selected, and the actual values of the path from different sources will vary.

① Select "Workspace default JRE (jdk1.7)", the value is

path="org.eclipse.jdt.launching.JRE_CONTAINER"
    • 1

② Select "Alternate JRE", the value is

path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7"
    • 1

The last of these jdk1.7 is my custom JRE name
③ Select "Execution Environment", that is, choose the built-in JRE from eclipse with a value of

path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"
    • 1

The last JavaSE-1.7 is the system's built-in JRE name
Additional attribute value Name= "Owner.project.facets"

<attribute name="owner.project.facets" value="java"/>
    • 1

Should be the specific use of the specified JRE container template, the default use of "Java", specifically not explored.

3.3.2 Server Runtime Configuration

Similarly, other container configurations, such as the configuration of the Server runtime container, are configured with the Tomcat container runtime environment

<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/学习 8080"/>
    • 1
3.3.3 Web App Libraries Configuration
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
    • 1
3.3.4 User Library Configuration
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/tomcat7"/>
    • 1
3.4 kind="lib"

kind="lib"Used to specify the referenced Libraries that project relies on, adding a jar package

The corresponding. classpath file contents increase

<classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-dbcp-1.2.1.jar"/>
    • 1

Where path Specifies the relative path of the dependent jar.

3.5 Order

The order of the nodes in the. classpath file is controlled by the Tab-order and Export, and the different order may cause problems with the loading class file, usually the source is in the front.

Copyright NOTICE: This article for Bo Master original article, the level is limited, welcome criticism and correction. http://blog.csdn.net/pengmm1990/article/details/68951389

. project file

<?xml version= "1.0" encoding= "UTF-8"?>
<projectDescription>
<name>CreateInterpret</name>
&LT;COMMENT&GT;JAVACC [email protected] 32303037303632392d3130303020437265617465496e746572707265742f777063 </ Comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>sf.eclipse.javacc.javaccbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>sf.eclipse.javacc.javaccnature</nature>
</natures>
</projectDescription>

From the data, we can see that these configurations are primarily about describing the basic engineering information:

    1. Project Name <name></name>
    2. Project Comment Description <comment></comment>
    3. Additional Eclipse plug-ins required by the runtime <natures></natures>, and their specific loading method information <buildSpec></buildSpec>

If you add a lot of additional plugins to your project during the development process, it will inevitably cause your eclipse to start slowly. In this case, you can remove some plugins from the file, but you will be able to load those plugins when you open those associated files.

what does path and classpath in Java mean specifically?
The path path is where the Java compiler needs to invoke a program (such as Java,javac, etc.) where the Classpath class is located, and when the Java program is compiled, if there is a call to another class, find the desired class in classpath.

A detailed description of the. classpath file in the Eclipse project

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.