1 Preface
When using eclipse or myeclipse for java project development, there will be a. classpath file under each project. What is the role of this file?
2 role
The. classpath file is used to record all the information of the project compilation environment, including: source file path, storage path of the compiled class file, dependent jar package path, running container information, dependent external project and other information. If the file is deleted, eclipse can't recognize the project as a normal java project, just as a normal folder, which leads to the failure of normal operation.
3. Classpath content
The. classpath file is also a content file in xml format. Its specific contents are as follows:
<?xml version="1.0" encoding="UTF-8"?> <classpath> <classpathentry kind="src" path="src"/> <classpathentry kind="src" path="resource"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7"> <attributes> <attribute name="owner.project.facets" value="java"/> </attributes> </classpathentry> <classpathentry kind="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> </classpathentry> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="output" path="WebContent/WEB-INF/classes"/> </classpath>
① Take "classpath" as the root node, and each "classpathentry" node represents a description information.
② Each "classpathentry" indicates the type with a "kind" attribute and "path" indicates the path.
③ All the contents of the above files are changed by the content change of "Java Build Path" in the project, that is, all the operations on "Java Build Path" will be reflected in the file content.
Now let's analyze the meaning of each node of the file content
3.1 kind="src"
src: that is, the source file. It 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 and. classpath are in the same directory and represent the source file.
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="resource"/>
The operation of kind = "src" corresponds to the "Source" tab page of "Java Build Path"
As shown in the figure below, add a folder bin as the source file, and the. classpath file will add content
The content is added as follows:
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="bin"/> <classpathentry kind="src" path="resource"/>
Of course, the contents of the. classpath file will change accordingly if you make corresponding modifications or deletions.
In addition, when the property combineaccessrules = false is specified, it means to introduce an external project, as follows
<classpathentry combineaccessrules="false" kind="src" path="/mybatis"/>
Corresponding page tab, where path = "/ mybatis", is the corresponding workspace
Absolute path.
3.2 kind="output"
output is used to specify the storage path of the compiled class file of the java source file. The format is as follows
<classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
Path: represents the path to store the class file. It is also the path to the. classpath file. Find "WebContent/WEB-INF/classes" and you can see the storage of the class file
If the output file path is modified, the corresponding content will also change
Change to: spring mybatis \ webcontent \ WEB-INF \ newclasses
Then the content of the. classpath file is modified to:
<classpathentry kind="output" path="WebContent/WEB-INF/newclasses"/>
3.3 kind="con"
con is the container, which is the container of program running, or the running environment is OK. In fact, it is specified in the installed JREs of Myeclipse at the beginning (in general, we specify JDK), but the jar package in JRE under JDK is actually used here, that is, JDK_HOME/jre/lib is the corresponding statement. The details are as follows
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7"> <attributes> <attribute name="owner.project.facets" value="java"/> </attributes> </classpathentry> <classpathentry kind="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> </classpathentry> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
The corresponding operation tab is as follows
3.3.1 JRE configuration
Path = "XXX" is used to specify the usage of jre container. Different sources of jre can be selected. The actual value of path from different sources will change
① Select "Workspace default JRE(jdk1.7)", then the value is
path="org.eclipse.jdt.launching.JRE_CONTAINER"
② If "Alternate JRE" is selected, the value is
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jdk1.7"
The last jdk1.7 is my custom JRE name
③ Select "Execution environment", that is, select the built-in jre provided by 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 Java se-1.7 is the JRE name built in the system
In addition, the attribute value name = "owner.project.facets"
<attribute name="owner.project.facets" value="java"/>
It should be the template that specifies the specific use of JRE container. By default, "java" is used, which is not explored.
3.3.2 Server Runtime configuration
Similarly, other container configurations are the same as above, such as the configuration of Server Runtime container. The tomcat container running environment is configured below
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Learning 8080"/>
3.3.3 configuration of web app Libraries
<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" refers to the Referenced Libraries that project depends on, as shown in the figure, a jar package is added
The content of the corresponding. classpath file is increased
<classpathentry kind="lib" path="WebContent/WEB-INF/lib/commons-dbcp-1.2.1.jar"/>
3.5 order
The order of the nodes in the. classpath file is controlled by tab order and export. Different order may cause the problem of loading the class file. Generally, the source code is placed first.