如何使用货物部署特定的子项目:开始使用Maven [英] How to deploy a specific child project with cargo:start using maven

查看:74
本文介绍了如何使用货物部署特定的子项目:开始使用Maven的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个开发的应用程序,我只是想简化构建过程.父级的POM文件如下所示:

<parent>
    <groupId>com.shc.obu.ca</groupId>
    <artifactId>shcobuca-pom</artifactId>
    <version>1.1.0</version>   </parent>

  <groupId>com.shc.obu.ca.osol</groupId> <artifactId>apps-pom</artifactId>   <version>${currVersion}</version>   <packaging>pom</packaging>   <name>Outlet Apps</name>

  <scm>
    <connection>scm:svn:https://ushofsvpsvn2.intra.searshc.com/svn/outlet/outlet/trunk/apps</connection>
    <developerConnection>scm:svn:https://ushofsvpsvn2.intra.searshc.com/svn/outlet/outlet/trunk/apps</developerConnection> </scm>
    <profiles>
    <profile> <id>www</id>
      <activation> <activeByDefault>true</activeByDefault> </activation>
      <modules>
        <module>www</module>
        <module>modules</module> 
      </modules>
    </profile>
    <profile> 
      <id>mts</id>
      <activation> <activeByDefault>true</activeByDefault> </activation>
      <modules>
        <module>mts</module> 
        <module>modules</module> 
      </modules>
    </profile>
    <profile> <id>search</id>
      <activation> <activeByDefault>true</activeByDefault> </activation>
      <modules>
        <module>modules</module> 
        <module>search</module> 
      </modules>
    </profile>   </profiles>

  <repositories>
    <repository>
      <id>obu.ca.repo.release</id>
      <snapshots><enabled>false</enabled></snapshots>
      <url>http://maven.cal.intra.sears.com/release</url>
    </repository>
    <repository>
      <id>obu.ca.repo.snapshot</id>
      <releases><enabled>false</enabled></releases>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>interval:5</updatePolicy>
      </snapshots>
      <url>http://maven.cal.intra.sears.com/snapshot</url>
    </repository>   </repositories>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <env>trunk</env>
    <currVersion>1.2.0</currVersion>   </properties>   </project>

此文件显示它具有三个配置文件,这些配置文件基本上是独立的子项目.我将货运插件添加到此文件中,如下所示:

<build>
  <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <container>
              <containerId>tomcat6x</containerId>
              <home>
                  C:\tools\apache-tomcat-6.0.26
              </home>
          </container>
          <configuration>
              <properties>
                  <cargo.servlet.port>
                      8082
                  </cargo.servlet.port>
                  <cargo.jvmargs>
                      "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n"
                  </cargo.jvmargs>
              </properties>
          </configuration>     
        </configuration>  
      </plugin>
  </plugins>
  </build>

但是当我运行'mvn cargo:start'时,tomcat实例运行良好,但是没有部署任何子应用程序.有什么方法可以自动部署我的第一个子应用程序(www)(该应用程序生成一个名为www-webapp-1.2.0.war的war文件)?

更新:谢谢Pascal.我尝试如下修改构建标记:

<build>
  <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <container>
              <containerId>tomcat6x</containerId>
              <home>
                  C:\tools\apache-tomcat-6.0.26
              </home>
          </container>
          <configuration>
              <properties>
                  <cargo.servlet.port>
                      8082
                  </cargo.servlet.port>
                  <cargo.jvmargs>
                      "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n"
                  </cargo.jvmargs>
              </properties>              
              <deployables> 
                <deployable> 
                  <groupId>com.shc.obu.ca.osol</groupId> 
                  <artifactId>www-webapp-1.2.0</artifactId> 
                  <type>war</type> 
                  <properties> 
                    <context>acontext</context> 
                  </properties> 
                </deployable> 
              </deployables>               
          </configuration>    
        </configuration>  
      </plugin>
  </plugins>
  </build>

但是仍然无法正常工作.它给出了如下的构建错误:

工件[com.shc.obu.ca.osol:www-webapp-1.2.0:war]不是项目的依赖项. 我也尝试将"www-webapp"和"www"作为工件ID,但错误仍然相同.

当我将其添加到依赖项标签时,它会给出某种循环引用错误,如下所示: 反应堆中的项目包含循环引用"

解决方案

您需要将www模块列出为要部署在<deployable>元素内的模块.从《 Maven2插件参考指南》 :

如果未指定可部署项目,并且项目的包装是war,ear或ejb,并且未指定部署者,则将生成的工件自动添加到要部署的可部署项目列表中

由于您的项目的类型为pompackaing,因此它不适合部署,也不会部署任何东西.

这里是一个例子:

  <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <container>
        <containerId>tomcat6x</containerId>
        <home>C:\tools\apache-tomcat-6.0.26</home>
      </container>
      <configuration>
        <properties>
          <cargo.servlet.port>8082</cargo.servlet.port>
          <cargo.jvmargs>
              "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n"
          </cargo.jvmargs>
        </properties>
        <deployables>
          <!-- application to deploy -->
          <deployable>
            <groupId>com.acme</groupId>
            <artifactId>mywebapp</artifactId>
            <type>war</type>
            <properties>
              <context>acontext</context>
            </properties>
          </deployable>
        </deployables>
      </configuration>     
    </configuration>  
  </plugin>

更新:

(...)出现如下构建错误

工件[com.shc.obu.ca.osol:www-webapp-1.2.0:war]不是项目的依赖项.我也尝试将"www-webapp"和"www"作为工件ID,但错误仍然相同.

我忘记了这一点,但是看起来Cargo希望deployable是启动Cargo的项目的依赖项.

当我将其添加到依赖项标签时,它会给出如下所示的循环引用错误:反应堆中的项目包含循环引用"

这是正常的.工件不能是给定项目的子模块和依赖项,否则您将获得循环依赖项(构建模块需要依赖项,即依赖项,鸡和蛋的问题).

我的建议是将货物配置移动到www模块或创建用于功能测试的专用模块(通常是我所做的),并声明www作为该模块的依赖项.

I have a developed application and I am just trying to make the build process easy. The POM file for parent looks like this:

<parent>
    <groupId>com.shc.obu.ca</groupId>
    <artifactId>shcobuca-pom</artifactId>
    <version>1.1.0</version>   </parent>

  <groupId>com.shc.obu.ca.osol</groupId> <artifactId>apps-pom</artifactId>   <version>${currVersion}</version>   <packaging>pom</packaging>   <name>Outlet Apps</name>

  <scm>
    <connection>scm:svn:https://ushofsvpsvn2.intra.searshc.com/svn/outlet/outlet/trunk/apps</connection>
    <developerConnection>scm:svn:https://ushofsvpsvn2.intra.searshc.com/svn/outlet/outlet/trunk/apps</developerConnection> </scm>
    <profiles>
    <profile> <id>www</id>
      <activation> <activeByDefault>true</activeByDefault> </activation>
      <modules>
        <module>www</module>
        <module>modules</module> 
      </modules>
    </profile>
    <profile> 
      <id>mts</id>
      <activation> <activeByDefault>true</activeByDefault> </activation>
      <modules>
        <module>mts</module> 
        <module>modules</module> 
      </modules>
    </profile>
    <profile> <id>search</id>
      <activation> <activeByDefault>true</activeByDefault> </activation>
      <modules>
        <module>modules</module> 
        <module>search</module> 
      </modules>
    </profile>   </profiles>

  <repositories>
    <repository>
      <id>obu.ca.repo.release</id>
      <snapshots><enabled>false</enabled></snapshots>
      <url>http://maven.cal.intra.sears.com/release</url>
    </repository>
    <repository>
      <id>obu.ca.repo.snapshot</id>
      <releases><enabled>false</enabled></releases>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>interval:5</updatePolicy>
      </snapshots>
      <url>http://maven.cal.intra.sears.com/snapshot</url>
    </repository>   </repositories>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <env>trunk</env>
    <currVersion>1.2.0</currVersion>   </properties>   </project>

This file shows that it has three profiles which are basically independent child project. I am adding the cargo plugin to this file as below:

<build>
  <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <container>
              <containerId>tomcat6x</containerId>
              <home>
                  C:\tools\apache-tomcat-6.0.26
              </home>
          </container>
          <configuration>
              <properties>
                  <cargo.servlet.port>
                      8082
                  </cargo.servlet.port>
                  <cargo.jvmargs>
                      "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n"
                  </cargo.jvmargs>
              </properties>
          </configuration>     
        </configuration>  
      </plugin>
  </plugins>
  </build>

But when I run 'mvn cargo:start', tomcat instance runs fine but none of the child apps get deployed. Is there a way that I can make my first child application (www) (which generates a war file called www-webapp-1.2.0.war) auto deployed?

Update: Thanks Pascal. I tried modifying the build tag as below:

<build>
  <plugins>
      <plugin>
        <groupId>org.codehaus.cargo</groupId>
        <artifactId>cargo-maven2-plugin</artifactId>
        <version>1.0</version>
        <configuration>
          <container>
              <containerId>tomcat6x</containerId>
              <home>
                  C:\tools\apache-tomcat-6.0.26
              </home>
          </container>
          <configuration>
              <properties>
                  <cargo.servlet.port>
                      8082
                  </cargo.servlet.port>
                  <cargo.jvmargs>
                      "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n"
                  </cargo.jvmargs>
              </properties>              
              <deployables> 
                <deployable> 
                  <groupId>com.shc.obu.ca.osol</groupId> 
                  <artifactId>www-webapp-1.2.0</artifactId> 
                  <type>war</type> 
                  <properties> 
                    <context>acontext</context> 
                  </properties> 
                </deployable> 
              </deployables>               
          </configuration>    
        </configuration>  
      </plugin>
  </plugins>
  </build>

But still it's not working. It's giving build error as below:

Artifact [com.shc.obu.ca.osol:www-webapp-1.2.0:war] is not a dependency of the project. I tried 'www-webapp' and 'www' as artifact id as well but the error remained the same.

And when I add the same to dependency tags, it gives some kind of cyclic reference error as below: 'The projects in the reactor contain a cyclic reference'

解决方案

You need to list your www module as a module to deploy inside a <deployable> element. From the Maven2 Plugin Reference Guide:

If no deployable is specified and the project's packaging is war, ear or ejb and there is no deployer specified then the generated artifact is added automatically to the list of deployables to deploy

Since your project has a packaing of type pom, it is not candidate for deployment and nothing gets deployed.

Here is an example:

  <plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <version>1.0</version>
    <configuration>
      <container>
        <containerId>tomcat6x</containerId>
        <home>C:\tools\apache-tomcat-6.0.26</home>
      </container>
      <configuration>
        <properties>
          <cargo.servlet.port>8082</cargo.servlet.port>
          <cargo.jvmargs>
              "-Xdebug" "-Xrunjdwp:transport=dt_socket,address=4646,server=y,suspend=n"
          </cargo.jvmargs>
        </properties>
        <deployables>
          <!-- application to deploy -->
          <deployable>
            <groupId>com.acme</groupId>
            <artifactId>mywebapp</artifactId>
            <type>war</type>
            <properties>
              <context>acontext</context>
            </properties>
          </deployable>
        </deployables>
      </configuration>     
    </configuration>  
  </plugin>

Update:

(...) It's giving build error as below

Artifact [com.shc.obu.ca.osol:www-webapp-1.2.0:war] is not a dependency of the project. I tried 'www-webapp' and 'www' as artifact id as well but the error remained the same.

I forgot about that but it looks like Cargo expect a deployable to be a dependency of the project where Cargo is started.

And when I add the same to dependency tags, it gives some kind of cyclic reference error as below: 'The projects in the reactor contain a cyclic reference'

Which is normal. An artifact can't be a sub-module and a dependency of a given project or you get a cyclic dependency (you need a dependency to build a module which is the dependency, chicken and egg problem).

My suggestion would be to move the cargo configuration to the www module or to create a dedicated module for your functional tests (this is usually what I do) and to declare www as dependency of this module.

这篇关于如何使用货物部署特定的子项目:开始使用Maven的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆