首先:项目上右击->configure->Convert to Maven Project 将项目转化为maven项目。 或者在.project文件中natures节添加java
<natures> <!-- ... --> <nature>org.eclipse.m2e.core.maven2Nature</nature> <!-- ... --> </natures>
完成pom.xml相关基础配置。而后修改build节使maven打包时兼容以前的项目路径配置。 ecplise 打开pom.xml文件选择effective POM 视图能够看到最终打包时的pom.xml的配置。web
配置在pom.xml中<build>节下的apache
<plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.2</version> <configuration> <webXml>WebContent\WEB-INF\web.xml</webXml><!-- web.xml文件路径 --> <!--设置项目根目录,默认为src/main/webapp --> <webappDirectory>${project.basedir}\target\WebContent</webappDirectory> <warSourceDirectory>${project.basedir}\WebContent</warSourceDirectory> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <!-- 指定maven打包JDK --> <configuration> <source>${java-version}</source> <target>${java-version}</target> <skip>true</skip> <!-- true:跳过测试 --> <encoding>UTF-8</encoding> <compilerArguments> <!-- 打包使须要添加的lib路径 --> <extdirs>${project.basedir}\WebContent\WEB-INF\lib</extdirs> </compilerArguments> </configuration> </plugin> </plugins>
尤为注意:tomcat
这样打包出来的war就是咱们想要的结构了。app
而后若是是ecplise+tomcat 启动项目的话,那么若是出现tomcat下项目结构不对,能够检查下.setter/org.eclipse.wst.common.component文件eclipse
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <wb-module deploy-name="ERCloud"> <wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/config"/> <wb-resource deploy-path="/WEB-INF/lib" source-path="/target/WebContent/WEB-INF/lib"/> <property name="java-output-path" value="/DEMO/target/WebContent/WEB-INF/classes"/> <property name="context-root" value="DEMO"/> </wb-module> </project-modules>