maven 构建javeee项目和maven项目热部署到tomcat web 容器上

一.进入dos环境
按开始键-->搜索程序和文件--->输入cmd
二.进入构建项目的目录路径 例如目标路径为: D:\workspace
首先:输入cd D:\workspace,然后按回车键。
其次:然后输入D: 按下回车键。
三.构建部署javaee项目
1.构建父项目
<1>mvn archetype:create -DgroupId=testmaven
                     -DartifactId=testmaven
                     -DpackageName=com.testmaven
<2>修改testmaven 文件夹内pom.xml
<packaging>jar</packaging>

<packaging>pom</packaging>
2.构建子项目模块
<1>进入testmaven路径
输入cd D:\workspace\testmaven,输入d:
<2>构建两个子项目模块 comm-core comm-web
dos命令为
mvn archetype:create -DgroupId=testmaven
                     -DartifactId=comm-core
                     -DpackageName=com.testmaven.core
mvn archetype:create -DgroupId=testmaven
                     -DartifactId=comm-web
                     -DpackageName=com.testmaven.web
                     -DarchetypeArtifactId=maven-archetype-webapp
<3>修改 comm-web 内的pom.xml配置文件
  <build> 
  <resources>
      <resource>
        <directory>src/main/resources</directory>
        <includes>
           <include>**/*.*</include>
        </includes>
      </resource>
    </resources> 
    <plugins>
      <plugin>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1.1</version>
    <configuration>
        <packagingExcludes>WEB-INF/web.xml</packagingExcludes>
    </configuration>
</plugin>        
      <plugin> 
        <groupId>org.codehaus.cargo</groupId> 
        <artifactId>cargo-maven2-plugin</artifactId> 
        <version>1.1.3</version> 
        <configuration> 
            <container> 
                <containerId>tomcat6x</containerId> 
                <type>remote</type> 
            </container> 
            <configuration> 
                <type>runtime</type> 
                <properties> 
                    <cargo.remote.username>admin</cargo.remote.username> 
                    <cargo.remote.password>admin</cargo.remote.password> 
                    <cargo.remote.manager.url>http://localhost:8080/manager/text</cargo.remote.manager.url> 
                </properties> 
            </configuration> 
        </configuration> 
      </plugin>
    </plugins>
  </build>
  <properties> 
        <finalName>testmaven</finalName>
  </properties>
3.热部署javaee项目
<1> 配置web容器 tomcat6x  tomcat-users.xml添加<tomcat-users>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <user username="admin" password="admin" roles="manager-gui,manager-script"/>
<2>Maven settings.xml 配置文件 配置
<pluginGroups>
    <!-- pluginGroup
     | Specifies a further group identifier to use for plugin lookup.
    <pluginGroup>com.your.plugins</pluginGroup>
    -->
     <pluginGroup>org.codehaus.cargo</pluginGroup>
</pluginGroups>

<servers>标签内添加
<server> 
       <id>tomcat</id> 
       <username>admin</username> 
       <password>admin</password> 
</server>

<3>在项目comm-web的pom.xml 内添加
<repositories>
      <repository>
    <id>codehaus-snapshots</id>
    <name>Codehaus Snapshots</name>
    <url>http://nexus.codehaus.org/snapshots/</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
    </repository>
  </repositories>

  <pluginRepositories>
  <pluginRepository>
    <id>codehaus-snapshots</id>
    <name>Codehaus Snapshots</name>
    <url>http://nexus.codehaus.org/snapshots/</url>
    <releases>
      <enabled>false</enabled>
    </releases>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
  </pluginRepository>
  </pluginRepositories>
<4>开启tomcat web容器
<5>在dos 环境输入
mvn install
mvn cargo:redeploy

注:项目部署的过程中,应该先对项目清理
先输入
mvn clean package
mvn install
mvn cargo:redeploy

<6>验证项目是否部署成功
在浏览器地址栏内输入:http://localhost:8080/testmaven/index.jsp


你可能感兴趣的:(maven,javaee,cargo)