tags:

views:

2540

answers:

2

I'm trying to use maven2 to build an axis2 project. My project is configured as a parent project with AAR, WAR, and EAR modules. When I run the parent project's package goal, the console shows a successful build and all of the files are created. However the AAR file generated by AAR project is not included in the generated WAR project. The AAR project is listed as a dependency of WAR project. When I explicitly run the WAR's package goal, the AAR file is then included in the WAR file.

Why would the parent's package goal not include the necessary dependency while running the child's package goal does?

I'm using the maven-war-plugin v2.1-alpha-2 in my war project.

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

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

Thanks, Joe

A: 

Have you tried using the "type" element in your dependencies? For example:

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

Its hard to say for sure what your problem is without seeing your actual pom files.

Update:

What happens if, from the parent project, you run:

 mvn clean install
  1. Does "install" have any different behavior than "package" as far as your problem is concerned?
  2. Do you see the .aar file in your local maven repository (~/.m2/repository/com/mycompany/.../)?

As a side note, i've never been very happy with the maven war plugin. I've always ended up using the maven assembly plugin. It just seems to work better and is more consistent. Also, make sure you are using the latest version of maven (2.0.9). I spent half a day fighting a similar problem which was fixed in the latest version.

+1  A: 

I was able to get my maven build working correctly by adding the following plugin to the ws-war pom file:

  <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>
Joe
That's too bad that you had to resort to using the dependency plugin, but I'm glad you got it to work. I'm thinking this is probably a bug in the war plugin though, you might want to post on the Maven usergroup and see if someone there can help you out.
Mike Deck