Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse with maven workspace dependency - packaged war contain folder instead of jar

I'm using Eclipse Kepler SR2 with m2e. I have a web project that depends on a jar.

When I use "Run as -> Maven Build..." with goal package and "Check Workspace artifacts" is checked, then the lib folder in the target contains a folder with the name of the dependency jar, instead of the jar itself. The packaged war also contains a folder instead of a jar. However, when deploying to tomcat with m2e, the jar is deployed correctly.

I use maven-war-plugin version 2.4.

This is my WAR pom:

<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>
  <parent>
    <groupId>com.modelity.loans</groupId>
    <artifactId>loans-parent</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </parent>
  <artifactId>loans-web</artifactId>
  <packaging>war</packaging>

  <dependencies>
    <dependency>
        <groupId>com.modelity.loans</groupId>
        <artifactId>loans-core</artifactId>
        <version>0.0.1-SNAPSHOT</version>
        <type>jar</type>
    </dependency>
  </dependencies>


  <build>
      <plugins>
            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
        </plugin>
      </plugins>
  </build>
</project>

And this is the artifact coordinates of the dependency jar:

<parent>
    <groupId>com.modelity.loans</groupId>
    <artifactId>loans-lib</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>loans-core</artifactId>
<packaging>jar</packaging>

I've looked at the debug output of the maven package goal. When the war plugin is processing the jars, it says

[DEBUG] Processing: loans-core-0.0.1-SNAPSHOT.jar

without indicating the jar has been copied. Later on in the log I see:

adding directory WEB-INF/lib/loans-core-0.0.1-SNAPSHOT.jar/

I've tried both embedded maven (3.0.4) and external maven (3.0.5). My colleague uses kepler SR1, and experience the same problem.

I think I've covered it all. Would be happy for some advise, couldn't find any reported bug about it.

Thanks, Lior

like image 778
Lior Chaga Avatar asked Nov 11 '22 08:11

Lior Chaga


1 Answers

Try installing the jar as its own maven-controlled artifact:

mvn install:install-file -Dfile=my.jar -DgroupId=com.mycorp -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar

And then define it as a maven dependency for your war

like image 190
Chris Gerken Avatar answered Nov 15 '22 07:11

Chris Gerken