Java Web项目中 的.classpath、.mymetadata、.project文件的作用
昨天因为编写的Servlet文件编译后生成的.class文件没在项目的WebContent/WEBINF/classes目录下,导致各种报错
原因是我的项目的.class文件都在build路径下
既然项目中存在.class文件
怎么放在build中就报错,在WebContent/WEBINF/classes目录下就可以运行呢
原来和项目的.classpath文件配置有关
正好对Java Web项目中的.classpath、.mymetadata、.project三个文件还不熟悉
就干脆一起学了
1、.classpath文件
【用途】.classpath的位置定义了你这个项目在编译时所使用的$CLASSPATH,配置整个工程的运行环境。
.classpath文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_144">
<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/Apache Tomcat v9.0">
<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>
看到这里,我发现了昨天报错的原因了
重点在这一句:
<classpathentry kind="output" path="WebContent/WEB-INF/classes"/>