码迷,mamicode.com
首页 > Web开发 > 详细

8.Eclipse中创建Maven Web项目

时间:2014-10-19 01:27:02      阅读:326      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   os   ar   java   sp   



第一步:

创建maven web工程

注意下面一步:

bubuko.com,布布扣

第二步:

继承parent

修改pom.xml文件如下

<projectxmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

 <modelVersion>4.0.0</modelVersion>

 <groupId>cn.toto.maven</groupId>

 <artifactId>web</artifactId>

 <packaging>war</packaging>

 <name>web Maven Webapp</name>

 <url>http://maven.apache.org</url>

 

  <parent> 

   <groupId>cn.toto.maven</groupId>

    <artifactId>Parent</artifactId>

    <version>0.0.1-RELEASE</version>

   <relativePath>../Parent/pom.xml</relativePath> 

 </parent>

 

 <dependencies>

   <dependency>

     <groupId>junit</groupId>

      <artifactId>junit</artifactId>

   </dependency>

   <dependency>

     <groupId>cn.toto.maven</groupId>

     <artifactId>MakeFriends</artifactId>

   </dependency>

 </dependencies>

 

</project>

 

第三步:

建立测试jsp

<%@ page language="java"contentType="text/html; charset=UTF-8"

    pageEncoding="UTF-8"%>

<%@ pageimport="cn.toto.maven.MakeFriends.*"%>

<%

    MakeFriendsmakeFriends=new MakeFriends();

   out.println(makeFriends.makeFriends("wanglipeng"));

%>

 

第四步:

自动部署到tomcat下面(web项目下的pom.xml)

<build>

   <finalName>web</finalName>

   <plugins>

         <plugin>

             <groupId>org.codehaus.cargo</groupId>

             <artifactId>cargo-maven2-plugin</artifactId>

             <version>1.2.3</version>

             <configuration>

                 <container>

                     <containerId>tomcat7x</containerId>

                     <!下面是Tomcat在电脑上的位置à

                     <home>D:/Program Files/ApacheSoftware Foundation/Tomcat 5.0</home>

                 </container>

                 <configuration>

                     <type>existing</type>

                     <home>D:/Program Files/ApacheSoftware Foundation/Tomcat 5.0</home>

                 </configuration>

             </configuration>

             <executions> 

                 <execution> 

                     <id>cargo-run</id> 

                     <phase>install</phase> 

                     <goals> 

                         <goal>run</goal> 

                     </goals> 

                 </execution> 

             </executions>

         </plugin>

     </plugins>

  </build>

 

第五步:

模块聚合

修改parent.pom

 

Web模块中的完整的pox.xml如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <artifactId>web</artifactId>

  <packaging>war</packaging>

 

  <name>web Maven Webapp</name>

 

   <parent> 

        <groupId>cn.toto.maven</groupId>

        <artifactId>Parent</artifactId>

        <version>0.0.1-SNAPSHOT</version>

        <relativePath>../Parent/pom.xml</relativePath> 

  </parent>

  <dependencies>

  <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

    </dependency>

    <dependency>

      <groupId>cn.toto.maven</groupId>

      <artifactId>MakeFriends</artifactId>

    </dependency>

</dependencies>

  <build>

    <finalName>web</finalName>

    <plugins>

          <plugin>

              <groupId>org.codehaus.cargo</groupId>

              <artifactId>cargo-maven2-plugin</artifactId>

             <version>1.2.3</version>

             <configuration>

                 <container>

                     <containerId>tomcat7x</containerId>

                      <!下面是Tomcat在电脑上的位置à

                     <home>D:/Program Files/Apache Software Foundation/Tomcat 5.0</home>

                 </container>

                 <configuration>

                     <type>existing</type>

                     <home>D:/Program Files/Apache Software Foundation/Tomcat 5.0</home>

                 </configuration>

             </configuration>

             <executions> 

                  <execution> 

                      <id>cargo-run</id> 

                      <phase>install</phase> 

                      <goals> 

                          <goal>run</goal> 

                      </goals> 

                  </execution> 

              </executions>

          </plugin>

      </plugins>

  </build>

 

</project>

注意:

 

Parent中的pom.xml如下:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

 

  <groupId>cn.toto.maven</groupId>

  <artifactId>Parent</artifactId>

  <version>0.0.1-SNAPSHOT</version>

  <packaging>pom</packaging>

 

  <name>Parent</name>

  <url>http://maven.apache.org</url>

<modules>

    <module>../Hello</module> 

    <module>../HelloFriend</module>   

    <module>../MakeFriends</module>

    <module>../web</module>

</modules>

  <properties>

    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

  </properties>

 

  <dependencyManagement>

  <dependencies>

    <dependency>

      <groupId>junit</groupId>

      <artifactId>junit</artifactId>

      <version>4.9</version>

      <scope>test</scope>

    </dependency>

    <dependency>

      <groupId>cn.toto.maven</groupId>

      <artifactId>HelloFriend</artifactId>

      <version>0.0.1-SNAPSHOT</version>

      <scope>compile</scope>

    </dependency>

    <dependency>

           <groupId>cn.toto.maven</groupId>

           <artifactId>Hello</artifactId>

           <version>0.0.1-SNAPSHOT</version>

           <scope>compile</scope>

       </dependency>

       <dependency>

           <groupId>cn.toto.maven</groupId>

           <artifactId>MakeFriends</artifactId>

           <version>0.0.1-SNAPSHOT</version>

           <scope>compile</scope>

       </dependency>

  </dependencies>

</dependencyManagement>

<distributionManagement>

    <repository>

        <id>releases</id>

        <name>Internal Releases</name>

        <url>http://localhost:8080/nexus-2.1.2/content/repositories/releases/</url>

    </repository>

    <snapshotRepository>

        <id>snapshots</id>

        <name>Internal Snapshots</name>

        <url>http://localhost:8080/nexus-2.1.2/content/repositories/snapshots/</url>

    </snapshotRepository>

  </distributionManagement>

 

</project>

 

 

8.Eclipse中创建Maven Web项目

标签:style   blog   http   color   io   os   ar   java   sp   

原文地址:http://blog.csdn.net/tototuzuoquan/article/details/40248209

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!