eclipse中maven專案部署到tomcat
阿新 • • 發佈:2019-01-02
其實maven專案部署到tomcat的方式很多,我從一開始的打war包到tomcat/webapps目錄,到使用tomcat-maven外掛,到直接使用servers部署,一路來走過很多彎路。
下面就一一介紹這幾種部署方式:
1.maven web專案部署到eclipse 編輯器上的tomcat.
這種方式其實跟非maven專案沒什麼區別,就是部署的方式不同
之後複製到tomcat/webapps目錄即完成部署。
2、使用tomcat-maven外掛,在pom.xml的</dependencies>之後新增以下程式碼,並做相應修改
這樣就配置好了tomcat maven外掛<build> <finalName>guoguo-maven-web</finalName> <plugins> <plugin> <!-- 3個可用外掛 --> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat6-maven-plugin</artifactId> <!-- 命令為tomcat6:redeploy --> <!-- <groupId>org.apache.tomcat.maven</groupId> --> <!-- <artifactId>tomcat7-maven-plugin</artifactId> --> <!-- 命令為tomcat7:redeploy --> <!-- <groupId>org.codehaus.mojo</groupId> --> <!-- <artifactId>tomcat-maven-plugin</artifactId> --> <!-- 命令為tomcat:redeploy --> <!-- <version>2.2</version> --> <configuration> <!-- <url>http://localhost:8080/manager</url> --> <!-- tomcat6部署管理路徑 --> <url>http://localhost:8080/manager/text</url> <!-- tomcat7部署管理路徑 --> <username>admin</username> <!-- tomcat的管理員賬號 --> <password>admin</password> <port>8080</port> <path>/guoguo-maven-web</path> <!-- 部署路徑 --> <charset>UTF-8</charset> <encoding>UTF-8</encoding> <!-- 執行redeploy命令前,要能正常訪問http://localhost:8080/manager--> </configuration> </plugin> </plugins> </build>
通過專案右鍵
run as --> maven build... --> main --> goals 中填入 tomcat:redeploy命令即可部署成功,這樣部署有時會使tomcat出錯,出錯需要重啟tomcat。
3.直接使用servers部署
首先確保編譯配置正常
test下的目錄編譯到target/test-classes,其他編譯到target/classes目錄即可,其他一般預設不需要改變什麼
然後進行部署的配置: