很多初学者,在用MyEcplise构建javaWeb项目是都会有一个疑惑,也可以说是一个通病吧,有时候把项目名改了,但是换了一台电脑就不行了。有时候甚至气的想摔电脑有没有?
其实我们可以看看,我们创建Web项目是都有什么文件。
我们可以看到除了必须的src和WebRoot外还有三个文件,一个文件夹。.myecplise这个文件夹。这其实就像一个标志一样,比如IDEA的就是.idea。
下面的.setting则是存的一些架包。
再下面则是.classpath文件
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="melibrary.com.genuitec.eclipse.j2eedt.core.MYECLIPSE_JAVAEE_6_CONTAINER"/>
<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="WebRoot/WEB-INF/classes"/>
</classpath>
这是内部的代码,其实就是一段配置。类似我们的xml。第一行,自然是定义格式之类的。下面呢,则是一些路径。可以看到最后一行是编译后的java文件,储存格式为class。
<?xml version="1.0" encoding="UTF-8"?>
<project-module
type="WEB"
name="EL and JSTL"
id="myeclipse.1539758233566"
context-root="/EL and JSTL"
j2ee-spec="6.0"
archive="EL and JSTL.war">
<attributes>
<attribute name="webrootdir" value="WebRoot" />
</attributes>
</project-module>
接着,下面的.mymetadata文件,则是配置整体Web的,project就是一个项目的意思,内部都是属性,name自然是项目名,context-root这个自然是页面访问时的地址,archive这个是打成的war包。
下面还有一个.project就是和我说的那个问题有关系的啦。
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>EL and JSTL</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.jsdt.core.javascriptValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.WebClasspathBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.J2EEProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.genuitec.eclipse.j2eedt.core.DeploymentDescriptorValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>com.genuitec.eclipse.j2eedt.core.webnature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
</natures>
</projectDescription>
我们可以看到第一个标签name,那个就是项目名,之后的<buildCommand>这个标签就是我们导入的架包的构建路径。也就是在lib包下的。
<natures>这个标签内则是架包配置。