我正在尝试使用 maven2 构建 axis2 项目。我的项目配置为具有 AAR、WAR 和 EAR 模块的父项目。当我运行父项目的包目标时,控制台显示构建成功并且所有文件都已创建。但是,AAR 项目生成的 AAR 文件不包含在生成的 WAR 项目中。AAR 项目被列为 WAR 项目的依赖项。当我显式运行 WAR 的包目标时,AAR 文件就会包含在 WAR 文件中。

为什么父包目标在运行子包目标时不包含必要的依赖项?

我在我的 war 项目中使用 maven-war-plugin v2.1-alpha-2 。

父 POM:

<parent>
    <groupId>companyId</groupId>
    <artifactId>build</artifactId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>com.nationwide.nf</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<version>1.0.0-SNAPSHOT</version>
<modules>
    <module>ws-war</module>
    <module>ws-aar</module>
    <module>ws-ear</module>
</modules>

AAR POM:

<parent>
    <artifactId>parent</artifactId>
    <groupId>companyId</groupId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>companyId</groupId>
<artifactId>ws-aar</artifactId>
<version>1.0.0-SNAPSHOT</version>
<description/>
<packaging>aar</packaging>
<dependencies>...</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.5</source>
                <target>1.5</target>
            </configuration>
        </plugin> 

        <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-wsdl2code-maven-plugin</artifactId>
            <version>1.4</version>
            <configuration>...</configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>wsdl2code</goal>
                    </goals>
                    <id>axis2-gen-sources</id>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.axis2</groupId>
            <artifactId>axis2-aar-maven-plugin</artifactId>
            <version>1.4</version>
            <extensions>true</extensions>
            <configuration>...</configuration>
        </plugin>
    </plugins>
</build>

战争POM:

<parent>
    <artifactId>parent</artifactId>
    <groupId>companyId</groupId>
    <version>1.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>companyId</groupId>
<artifactId>ws-war</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<description/>
<dependencies>
    <dependency>
        <groupId>companyId</groupId>
        <artifactId>ws-aar</artifactId>
        <type>aar</type>
        <version>1.0.0-SNAPSHOT</version>
    </dependency>
    .
    .
    .
</dependencies>
<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.1-alpha-2</version>
            <configuration>
                <warName>appName</warName>
            </configuration>
        </plugin>
    </plugins>
</build>

谢谢,乔

有帮助吗?

解决方案

通过将以下插件添加到 ws-war pom 文件,我能够使我的 Maven 构建正常工作:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>
                            ${project.build.directory}/${project.build.finalName}/WEB-INF/services
                        </outputDirectory>
                        <includeArtifactIds>
                            ws-aar
                        </includeArtifactIds>
                    </configuration>
                </execution>
            </executions>
        </plugin>

其他提示

您是否尝试过在依赖项中使用“type”元素?例如:

<dependency>
  <groupId>group-a</groupId>
  <artifactId>artifact-b</artifactId>
  <version>1.0</version>
  <type>aar</type>
</dependency>

如果没有看到实际的 pom 文件,很难确定你的问题是什么。

更新:

如果从父项目运行以下命令,会发生什么情况:

 mvn clean install
  1. 就您的问题而言,“安装”与“软件包”有什么不同的行为吗?
  2. 您是否在本地 Maven 存储库 (~/.m2/repository/com/mycompany/.../) 中看到 .aar 文件?

顺便说一句,我对 Maven War 插件一直不太满意。我总是最终使用 Maven 程序集插件。它似乎工作得更好并且更一致。另外,请确保您使用的是最新版本的 maven (2.0.9)。我花了半天时间解决了类似的问题,该问题已在最新版本中修复。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top