Question

I included a project as dependency in another project. On maven package the included dependency is not compiled as jar, but an empty folder is created.

projects:

main-test (packaging: jar)
main-webservice (packaging: war)

the main-webservice project includes the jar with pom.

main-test pom.xml:

<?xml version="1.0"?>
<project
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
    xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <modelVersion>4.0.0</modelVersion>

    <groupId>de.main</groupId>
    <artifactId>test</artifactId>
    <packaging>jar</packaging>
</project>

main-webservice 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>de.main</groupId>
    <artifactId>ws</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>

<dependencies>
    <dependency>
        <groupId>de.main</groupId>
        <artifactId>test</artifactId>
        <version>1.0</version>
    </dependency>
</dependencies>
<build><plugin>

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

The dependencies of the test project are resolved inside webservice project, so the pom seems to be correct.

Anyhow, if I run "mvn package", the resources of main-webservices compile to target, but the libs folder contains another folder named main-test-1.0.jar. BUT it's a folder, not a packed jar.

What could be wrong here? How can I get the project to be packaged as jar, not as folder?

Was it helpful?

Solution

included dependency is not compiled as jar

Maven never compiles dependencies. It just takes them as they are and either puts them on the classpath or copies them into the WAR. But it never changes the artifact.

That also means the dependency must be in your local repo (somewhere below ~/.m2/repository/) or Maven will be unhappy (= fail with an error).

Note: Maven doesn't have a big memory. It can always only keep a single module in his tiny brain. In Eclipse, you can add another project as it is to the build path but Maven can't do that. For Maven to work properly, you must install all the dependencies in your local repo.

OTHER TIPS

Idea:

  • Check if the jar exists in your repository

  • Check if the jar project in eclipse is not referenced in the war project in the Java Build Path

  • Do it without eclipse mvn plugin:

    mvn eclipse:clean (for both projects)

    mvn eclipse:eclipse (for both projects)

    mvn clean install (for both projects)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top