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

发布于 2024-09-08 05:22:45 字数 5590 浏览 10 评论 0原文

我有一个开发的应用程序,我只是想让构建过程变得简单。父项目的 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 文件)自动部署?

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

<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,但错误仍然相同。

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

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'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

递刀给你 2024-09-15 05:22:45

您需要将 www 模块列为要在 元素内部署的模块。来自 Maven2 插件参考指南

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

因为您的项目具有 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>

更新:

(...)它给出了如下构建错误

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

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

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

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

我的建议是将货物配置移动到 www 模块,或者为功能测试创建一个专用模块(这通常是我所做的)并将 www 声明为该模块的依赖关系。

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.

橘亓 2024-09-15 05:22:45

以下是如何使用 Cargo 进行多模块部署的示例。它有一个父模块和三个模块,其中一个模块负责所有三个模块和货物的部署。您可以从第三个模块运行 mvn Cargo:run 来部署所有这些模块。

==================== PARENT 1 =========================

<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>
    <groupId>com.blah.test</groupId>
    <artifactId>blah-service</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>blah-service-module1</module>
        <module>blah-service-module2</module>
        <module>blah-service-module3</module>
    </modules>
</project>

==================== MODULE 1 =========================

<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>
    <parent>
        <groupId>com.blah.test</groupId>
        <artifactId>blah-service</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>blah-service-module1</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
</project>

==================== MODULE 2 =========================

<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>
    <parent>
        <groupId>com.blah.test</groupId>
        <artifactId>blah-service</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>blah-service-module2</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
</project>

========== MODULE 3: the one which deploys all three with cargo =========================

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

    <parent>
        <groupId>com.blah.test</groupId>
        <artifactId>blah-service</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>blah-service-module3</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.blah.test</groupId>
            <artifactId>blah-service-module1</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>com.blah.test</groupId>
            <artifactId>blah-service-module2</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.4.6</version>
                <configuration>
                    <container>
                        <containerId>jetty6x</containerId>
                        <type>embedded</type>
                    </container>
                    <deployables>
                        <deployable>
                            <groupId>com.blah.test</groupId>
                            <artifactId>blah-service-module1</artifactId>
                            <type>war</type>
                            <properties>
                                <context>api/blah/module1</context>
                            </properties>
                        </deployable>
                        <deployable>
                            <groupId>com.blah.test</groupId>
                            <artifactId>blah-service-module2</artifactId>
                            <type>war</type>
                            <properties>
                                <context>api/blah/module2</context>
                            </properties>
                        </deployable>
                        <deployable>
                            <groupId>com.blah.test</groupId>
                            <artifactId>blah-service-module3</artifactId>
                            <type>war</type>
                            <properties>
                                <context>api/blah/module3</context>
                            </properties>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Here is a sample of how to do multi-module deployments with Cargo. It has a parent and three modules, where one of them does the deployment of all three with cargo. You can run mvn cargo:run from the third module to get all of them deployed.

==================== PARENT 1 =========================

<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>
    <groupId>com.blah.test</groupId>
    <artifactId>blah-service</artifactId>
    <packaging>pom</packaging>
    <version>1.0-SNAPSHOT</version>
    <modules>
        <module>blah-service-module1</module>
        <module>blah-service-module2</module>
        <module>blah-service-module3</module>
    </modules>
</project>

==================== MODULE 1 =========================

<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>
    <parent>
        <groupId>com.blah.test</groupId>
        <artifactId>blah-service</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>blah-service-module1</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
</project>

==================== MODULE 2 =========================

<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>
    <parent>
        <groupId>com.blah.test</groupId>
        <artifactId>blah-service</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>blah-service-module2</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
</project>

========== MODULE 3: the one which deploys all three with cargo =========================

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

    <parent>
        <groupId>com.blah.test</groupId>
        <artifactId>blah-service</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>blah-service-module3</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>com.blah.test</groupId>
            <artifactId>blah-service-module1</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
        <dependency>
            <groupId>com.blah.test</groupId>
            <artifactId>blah-service-module2</artifactId>
            <version>1.0-SNAPSHOT</version>
            <type>war</type>
        </dependency>
    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.cargo</groupId>
                <artifactId>cargo-maven2-plugin</artifactId>
                <version>1.4.6</version>
                <configuration>
                    <container>
                        <containerId>jetty6x</containerId>
                        <type>embedded</type>
                    </container>
                    <deployables>
                        <deployable>
                            <groupId>com.blah.test</groupId>
                            <artifactId>blah-service-module1</artifactId>
                            <type>war</type>
                            <properties>
                                <context>api/blah/module1</context>
                            </properties>
                        </deployable>
                        <deployable>
                            <groupId>com.blah.test</groupId>
                            <artifactId>blah-service-module2</artifactId>
                            <type>war</type>
                            <properties>
                                <context>api/blah/module2</context>
                            </properties>
                        </deployable>
                        <deployable>
                            <groupId>com.blah.test</groupId>
                            <artifactId>blah-service-module3</artifactId>
                            <type>war</type>
                            <properties>
                                <context>api/blah/module3</context>
                            </properties>
                        </deployable>
                    </deployables>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文