2

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.

Carl Walsh
  • 6,100
  • 2
  • 46
  • 50
Ghetolay
  • 3,222
  • 2
  • 30
  • 29
  • This might be trivial, but which version has the jar in the first pom? Are you sure it's 0.0.1-SNAPSHOT? – Ria Mar 24 '15 at 18:37
  • yes, well I wanted to purge the pom content but it's not that big so I've now copy paste the entire file content. – Ghetolay Mar 25 '15 at 11:29
  • @Ghetolay I'm not clear with your question. Are you saying that if you run the POM file as "Run as Maven build" everything ok. But if you running it as 'Run as...' web server on your project it not ok.? – Sumit Singh Mar 26 '15 at 10:38

1 Answers1

0

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.

3urdoch
  • 7,192
  • 8
  • 42
  • 58
  • The mapping for jar:jar is set as `configurator`, don't really know what it means. Also I'm unable to find any doc about the `lifecycle mappings metadata` xml file so I don't know how to change it from `configurator` to `execute`. – Ghetolay Mar 25 '15 at 12:37
  • well I was about to try with some content on `lifecycle-mapping-metadata.xml` and it seems to work. Even when I reverted back my changes. This may have been a temporary bug fixed with some upgrade. I'll do some more test later. – Ghetolay Mar 25 '15 at 13:06
  • @Ghetolay 'configurator' means you have to do a Maven > Update Project, so you perhaps had not previously done that and now you have. Maven > Update project synchronises the configuration between the pom file and your eclipse projects. – 3urdoch Mar 25 '15 at 13:18