maven-2 - 如何使用 cargo :start using maven部署特定的子项目

标签 maven-2 cargo maven-cargo

我有一个开发的应用程序,我只是想让构建过程变得简单。父级的 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>

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

<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 文件)自动部署?

更新:谢谢帕斯卡。我尝试修改构建标签如下:

<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>

但是仍然不起作用。它给出的构建错误如下:

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

当我将相同的内容添加到依赖标记时,它会给出某种循环引用错误,如下所示: “ react 器中的项目包含循环引用”

最佳答案

您需要列出您的www module 作为部署在 <deployable> 内的模块元素。来自 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

由于您的项目有 packaing类型 pom ,它不是部署的候选者,并且没有部署任何内容。

这是一个例子:

  <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>

更新:

(...) 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.

我忘了这一点,但看起来 Cargo 期望 deployable成为启动 Cargo 的项目的依赖项。

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'

这很正常。工件不能是给定项目的子模块和依赖项,否则您将获得循环依赖项(您需要一个依赖项来构建模块,这就是依赖项,先有鸡还是先有蛋的问题)。

我的建议是将 cargo 配置移至www模块或为功能测试创建专用模块(这通常是我所做的)并声明 www作为该模块的依赖项。

关于maven-2 - 如何使用 cargo :start using maven部署特定的子项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3179181/

相关文章:

java - 用于 cargo 内部集成测试的邮件服务器模拟

maven - 如何在 Maven 中绑定(bind)两个插件

tomcat - 从 cargo-maven2-plugin 以嵌入式模式启动 tomcat 的最简单方法是什么?

deployment - gradle-cargo-plugin : How to add jars to the server's lib directory?

java - Sonar 不显示代码覆盖率

maven-2 - Maven : How to use jetty:run in a multi-module Maven project, 无需安装

tomcat - 使用 gradle 检查应用程序是否部署在 Tomcat 中

tomcat - 如何使用 Maven 将我的 Web 应用程序和 tomcat 打包在一起?

maven-2 - 如何使用 Maven 打包 jar 并在 WEB-INF/lib 中包含一些依赖项?

java - Maven 不使用 Java 7