Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven add jars through systemPath/system but not added to war or anywhere else

Tags:

java

maven

I want to add a jar file through the systemPath from the local file-system relative to my project directory structure, not on a remote repository. I added the dependency declaration but maven doesn't do anything else with it.

In the declaration below, I want the jar file copied to my target web-inf/lib directory and also jarred as part of the war file. At present, that doesn't happen. How would I get the jar file copied to my war file?

This is the output from debug maven mode:

DEBUG] cglib:cglib-nodep:jar:2.2:test (setting scope to: compile)^M
DEBUG] Retrieving parent-POM: org.objenesis:objenesis-parent:pom:1.2 for project: null:objenesis:ja
DEBUG]   org.objenesis:objenesis:jar:1.2:test (selected for test)^M
DEBUG]   org.javap.web:testRunWrapper:jar:1.0.0:system (selected for system)^M
DEBUG] Plugin dependencies for:
...


<dependency>
    <groupId>org.javap.web</groupId>
    <artifactId>testRunWrapper</artifactId>
    <version>1.0</version>
    <scope>system</scope>
    <systemPath>${basedir}/lib/testRunWrapper.jar</systemPath>
</dependency>
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>                 
        <webResources>
            <resource>
                <directory>WebContent</directory>
            </resource>
        </webResources>
    </configuration>
</plugin>
like image 930
Berlin Brown Avatar asked Apr 08 '11 15:04

Berlin Brown


People also ask

Can I add JARs to Maven 2 build classpath without installing them?

Maven install plugin has command line usage to install a jar into the local repository, POM is optional but you will have to specify the GroupId, ArtifactId, Version and Packaging (all the POM stuff). -1, sometimes you just want to add a jar file without the trouble of installing it.

Where does Maven install Put JARs?

You can find your installed JARs and dependencies in your local repository. By default, you can find it here: Windows: C:\Users\USERNAME\. m2\repository.

How do I resolve a missing jar in Maven repository?

Look in your . m2 directory (use the paths which you see in the dialog above) and check whether the files are there or whether they are really missing. If they are missing, run "mvn install" (see the "Run as..." menu) to download them.


2 Answers

Using the maven dependency plugin does the job:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.8</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>compile</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/lib</outputDirectory>
                        <includeScope>system</includeScope>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>
like image 42
Akram Ben Aissi Avatar answered Oct 24 '22 16:10

Akram Ben Aissi


OK, I did this: Note the directory structure at the bottom. With the approach below, the jar file from the relative project path is treated as a first class citizen like the other jars. The listing below corrects my original problem. With the pom.xml listing below, the jar file is copied to my target directory.

<repositories>
    <repository>
        <id>JBoss</id>
        <name>JBoss Repository</name>
        <layout>default</layout>
        <url>http://repository.jboss.org/maven2</url>
    </repository>

    <repository>
       <id>my-local-repo</id>
       <url>file://${basedir}/lib/repo</url>
    </repository>
</repositories>

<dependency>
    <groupId>testRunWrapper</groupId>
    <artifactId>testRunWrapper</artifactId>
    <version>1.0.0</version>            
</dependency>

$ find repo
repo
repo/testRunWrapper
repo/testRunWrapper/testRunWrapper
repo/testRunWrapper/testRunWrapper/1.0.0
repo/testRunWrapper/testRunWrapper/1.0.0/testRunWrapper-1.0.0.jar
like image 171
Berlin Brown Avatar answered Oct 24 '22 14:10

Berlin Brown