Stefan K.
Stefan K.

Reputation: 7851

Let MVN store libraries in MyProject/lib/?

I would like maven to store the dependent jars in the project specific lib folder instead of in the default MyUser/.m2/repository/. Not everybody has internet access when he gets the project, and copying the global local repository seems like a less-than-ideal solution.

How do I persuade maven to store and use these dependencies in a local, relative, project specific folder?

Seems my question is a rephrased version of this Stackoverflow question

I did something like this:

    <build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>${mvn-dependency-plugin.version}</version>
            <executions>
                <execution>
                    <id>copy-dependencies</id>
                    <phase>package</phase>
                    <goals>
                        <goal>copy-dependencies</goal>
                    </goals>
                    <configuration>
                        <outputDirectory>${project.basedir}/${local-lib-dir}</outputDirectory>
                        <overWriteReleases>false</overWriteReleases>
                        <overWriteSnapshots>false</overWriteSnapshots>
                        <overWriteIfNewer>true</overWriteIfNewer>
                        <stripVersion>true</stripVersion>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
    <build>

The only downside is, that eclipses maven still refer to the jars in the local repository.

Upvotes: 0

Views: 195

Answers (2)

khmarbaise
khmarbaise

Reputation: 97437

I'm sorry to say that, but if you really like to have a lib folder which contains the dependencies you are working with you are back in Ant times and start also checking in the lib folder into your version control which is really bad.

If you argument that an internet access does not exist you should start using a repository manager like Artifactory, Nexus or Archiva which is installed within the local network and only the repository manager needs the internet connection. Everyone else just uses a version control tool to checkout the sources and can start working with the project.

Upvotes: 1

Gerard Ribas
Gerard Ribas

Reputation: 727

You can manage your external dependencies like this:

<dependency>
    <groupId>mydependencygroup</groupId>
    <artifactId>my.artifact</artifactId>
    <scope>system</scope>
    <version>1.0</version>
    <systemPath>${basedir}\src\lib\myartifact.jar</systemPath>
</dependency>

The lib folder is inside your src folder.

Hope it hepls.

Upvotes: 0

Related Questions