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?

2 effects

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>      

① 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"/>

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"/>

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"/>

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

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"/>

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"/>

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"/>  

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"

② Select "Alternate JRE", the value is

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

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"

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"/>

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"/>
3.3.3 Web App Libraries Configuration
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
3.3.4 User Library Configuration
<classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/tomcat7"/>
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"/>

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.

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.