首先:項目上右擊->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>