使用Maven Cargo部署多模块项目

时间:2012-02-21 13:19:25

标签: maven maven-cargo

在我正在研究的这个项目中,我有一个庞大的主pom文件,定义了几个模块(域,dao,服务,战争)。

我想使用Cargo将我的战争部署到我的远程tomcat服务器。

运行mvn cargo:deploy -Ptest会给我一个错误,即模块dao中模块域的依赖关系无法解析。

我已经尝试将货物配置放在战争中,但仍然是相同的。

有人可以帮助我吗?

这是父POM

<?xml version="1.0" encoding="UTF-8"?>
<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.domain</groupId>
    <artifactId>product</artifactId>
    <version>1.2-SNAPSHOT</version>
    <packaging>pom</packaging>

    <dependencyManagement>
        <dependencies>
            <!-- Internal dependencies -->
            <dependency>
                <groupId>com.domain.product</groupId>
                <artifactId>product-domain</artifactId>
                <version>${project.version}</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.domain.product.dao</groupId>
                <artifactId>product-dao-api</artifactId>
                <version>${project.version}</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.domain.product.dao</groupId>
                <artifactId>product-dao-jpa2</artifactId>
                <version>${project.version}</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.domain.product.service</groupId>
                <artifactId>product-service-api</artifactId>
                <version>${project.version}</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.domain.product.service</groupId>
                <artifactId>product-service-impl</artifactId>
                <version>${project.version}</version>
                <type>jar</type>
                <scope>compile</scope>
            </dependency>
            <dependency>
                <groupId>com.domain.product</groupId>
                <artifactId>product-war</artifactId>
                <version>${project.version}</version>
                <type>jar</type>
                <type>war</type>
                <scope>compile</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <build>
        <pluginManagement>
            <plugins>
                <plugin>
                    <groupId>org.codehaus.cargo</groupId>
                    <artifactId>cargo-maven2-plugin</artifactId>
                    <version>1.2.0</version>
                </plugin>
            </plugins>
        </pluginManagement>
    </build>

    <!-- profiles -->
    <profiles>
        <profile>
            <id>test</id>
            <activation>
            <property>
                <name>environment.type</name>
                <value>test</value>
            </property>
            </activation>
            <properties>
            </properties>
        </profile>
    </profiles>

    <modules>
        <module>product-domain</module>
        <module>product-dao-api</module>
        <module>product-dao-jpa2</module>
        <module>product-service-api</module>
        <module>product-service-impl</module>
        <module>product-war</module>
    </modules>
</project>

这是WAR POM:

<?xml version="1.0" encoding="UTF-8"?>
<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>
        <artifactId>product</artifactId>
        <groupId>com.domain</groupId>
        <version>1.2-SNAPSHOT</version>
    </parent>
    <groupId>com.domain.product</groupId>
    <artifactId>product-war</artifactId>
    <name>product</name>
    <packaging>war</packaging>

    <dependencies>
        <dependency>
            <groupId>com.domain.product.service</groupId>
            <artifactId>product-service-impl</artifactId>
        </dependency>
        <dependency>
            <groupId>com.domain.product.service</groupId>
            <artifactId>product-service-api</artifactId>
        </dependency>
    </dependencies>

    <profiles>
        <profile>
            <id>test</id>
            <activation>
                <property>
                    <name>environment.type</name>
                    <value>test</value>
                </property>
            </activation>
            <properties>
                <!-- Deployment settings -->
                <cargo.containerId>tomcat7x</cargo.containerId>
                <cargo.baseurl>http://test.domain.net:8080</cargo.baseurl>
                <container.url>${cargo.baseurl}/manager/text</container.url>
                <container.user>tomcat-txt</container.user>
                <container.password>password</container.password>
                <container.pingurl>${cargo.baseurl}/${project.name}/index.html</container.pingurl>
            </properties>
            <build>
                <plugins>
                    <plugin>
                        <groupId>org.codehaus.cargo</groupId>
                        <artifactId>cargo-maven2-plugin</artifactId>
                        <configuration>
                            <wait>true</wait>
                            <container>
                                <containerId>${cargo.containerId}</containerId>
                                <type>remote</type>
                            </container>
                            <configuration>
                                <type>runtime</type>
                                <properties>
                                    <cargo.remote.uri>${container.url}</cargo.remote.uri>
                                    <cargo.remote.username>${container.user}</cargo.remote.username>
                                    <cargo.remote.password>${container.password}</cargo.remote.password>
                                </properties>
                            </configuration>
                            <deployer>
                                <deployables>
                                    <deployable>
                                        <groupId>com.domain.product</groupId>
                                        <artifactId>product-war</artifactId>
                                        <type>war</type>
                                        <properties>
                                            <context>${project.name}</context>
                                        </properties>
                                        <pingURL>${container.pingurl}</pingURL>
                                    </deployable>
                                </deployables>
                            </deployer>
                        </configuration>
                    </plugin>
                </plugins>
            </build>
        </profile>
    </profiles>
</project>

正如你所看到的,战争依赖于服务,服务本身依赖于dao和域中的那个。

1 个答案:

答案 0 :(得分:1)

在我看来,你必须首先使用mvn安装而不是

mvn -pl product-war cargo:deploy -Ptest