How do I get m2e-WTP to build jar dependencies with maven?

691 views Asked by At

I'm using eclipse luna and I have 2 maven projects : a web application and a java library which is a dependency of the web application.

library pom.xml :

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.test</groupId>
  <artifactId>library</artifactId>
  <verson>0.0.1-SNAPSHOT</version>
   <build>
    <plugins>
      <plugin>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.3.2</version>
        <configuration>
          <archive>
            <manifestEntries>
              <Dependencies>just a test</Dependencies>
            </manifestEntries>
          </archive>
        </configuration>
      </plugin>
    </plugins>
   </build>
</project>

webApp pom.xml :

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.test</groupId>
  <artifactId>webapp</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <dependencies>
    <dependency>
        <groupId>org.test</groupId>
        <artifactId>library</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>
</project>

Now when I deploy my war on a webserver (jboss) as 'Run as...',the war file is generated and it embed the library's jar under WEB-INF/lib. So everything seems fine except it's not : the generated jar was not generated by maven and it misses whatever configuration was set on the maven-jar-plugin (on this case the Dependencies: just a test line).

May be obvious but if I use 'Run as Maven build' on the library project both jar:jar and package goals builds a jar with the expected manifest.

1

There are 1 answers

3
3urdoch On

I have managed to archive this using the maven configurator.

  1. Add the plugin configuration you have provided to the pom.xml file
  2. Add the dependency to the webapp project
  3. Right click on the maven webapp project and go to Maven > Update project
  4. Select both the webapp and the library for good measure and click OK
  5. I'm using Tomcat, but when i clean the server and check the webapp directory, the jar file includes the manifest

If this didn't work, check that the jar:jar goal is not ignored in the Eclipse lifecycle mappings.

  1. Right click on the library project and click on Properties
  2. Go to: Maven > Lifecycle Mappings
  3. Check the jar:jar plugin execution, for me it did actually say Mapping: ignored, Source: workspace so i had to update my eclipse configuration

To remove jar:jar it from the ignored list for your workspace:

  1. Workspace Preferences > Maven > Lifecycle Mappings
  2. Open workspace lifecycle mappings metadata
  3. Edit the xml to remove the maven-jar-plugin plugin execution
  4. Save
  5. Click 'Reload workspace lifecycle mappings' or restart eclipse. I had to restart eclipse as this didn't take effect.
  6. Do a Maven > Update project on the effected projects again to make sure

The mapping may be ignored in the pom.xml file instead, in which case you will find a section on the library pom file under pluginManagement that ignores the plugin execution.