使用maven建立web項目

來源:互聯網
上載者:User

標籤:imp   atom   sds   diy   fps   fgetc   rda   ogg   lzw   

1.1 選擇建立Maven Project

  選擇File -> New ->Project,如所示:

  

  在New視窗中選擇 Maven -> Maven Project。點擊【next】如所示:

  

 

1.2 選擇項目路徑

  根據項目的實際情況選擇項目的存放目錄,也可以選擇【Use default Workspace location】預設工作空間。如所示:

  

1.3 選擇項目類型

  在Artifact Id中選擇maven-archetype-webapp,如所示:

  

1.4 輸入Group ID和 Artifact ID以及Package

  Group ID一般寫大項目名稱。Artifact ID是子項目名稱。

  例如Spring的web包,Group ID:org.springframework,artifactId:spring-web。

  Package是預設給你建一個包,不寫也可以。如所示:

  

1.5 項目建立好後的檔案結構

  剛建立好後的檔案結構如如如所示:

  

二、將Web項目自動部署到tomcat伺服器2.1、在pom.xml檔案中配置tomcat伺服器

  配置web項目的pom.xml檔案,配置如下:

 1 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3   <modelVersion>4.0.0</modelVersion> 4   <groupId>me.gacl.maven</groupId> 5   <artifactId>WebProject</artifactId> 6   <packaging>war</packaging> 7   <version>0.0.1-SNAPSHOT</version> 8   <name>WebProject Maven Webapp</name> 9   <url>http://maven.apache.org</url>10   <dependencies>11     <dependency>12       <groupId>junit</groupId>13       <artifactId>junit</artifactId>14       <version>3.8.1</version>15       <scope>test</scope>16     </dependency>17   </dependencies>18   19   <!-- 將Web項目自動部署到tomcat伺服器的相關 配置資訊-->20   <build>21       <!-- 將WebProject項目打包成WebProject.war自動部署到tomcat伺服器的webapps目錄下面 -->22     <finalName>WebProject</finalName>23     <plugins>24           <plugin>25               <groupId>org.codehaus.cargo</groupId>26               <artifactId>cargo-maven2-plugin</artifactId>27                 <version>1.2.3</version>28                 <configuration>29                     <container>30                           <!-- 指明使用的tomcat伺服器版本 -->31                         <containerId>tomcat7x</containerId>32                         <!--指明tomcat伺服器的安裝目錄 -->33                         <home>D:/apache-tomcat-7.0.53</home>34                     </container>35                     <configuration>36                         <type>existing</type>37                         <!--指明tomcat伺服器的安裝目錄 -->38                         <home>D:/apache-tomcat-7.0.53</home>39                     </configuration>40                 </configuration>41                 <executions>  42                   <execution>  43                       <id>cargo-run</id>  44                       <phase>install</phase>  45                       <goals>  46                           <goal>run</goal>  47                       </goals>  48                   </execution>  49               </executions>50           </plugin>51       </plugins>52   </build>53 </project>
2.2、將web項目發布到tomca伺服器的webapps目錄

  選中Web項目(或者選中Web項目的pom.xml檔案)→【Run As】→【Maven install】,如所示:

  

  執行完【Maven install】命令之後,就可以將WebProject項目打包成WebProject.war包發布到tomca伺服器的webapps目錄下,如所示:

  

  測試部署好的Web項目,如所示:

  

  瀏覽器正常輸出了index.jsp頁面中的內容,這說明我們的部署成功了。這就是在Eclipse中使用Maven將Web項目自動部署到tomcat伺服器的過程。

使用maven建立web項目

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.