Reputation: 105133
I need to use a third-party JAR library in my project (actually it's Dresden OCL for Eclipse) that is not provided as a Maven artifact. Instead, it's just a downloadable JAR file. Can I instruct Maven to use this JAR file the same way I'm using <dependencies>
? I suppose that there should be some plugin for this purpose?
ps. I just don't want to add 35Mb of third-party binaries into my SVN repository.
Would be nice to have it configured this way:
<build>
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>non-maven-dependencies-injector</artifactId>
<configuration>
<libraries>
<library>http://www.example.com/something*.jar</library>
<library>http://www.example.com/something-else*.jar</library>
</libraries>
</configuration>
</plugin>
<plugins>
</build>
And this plugin would 1) download these JAR files, and 2) add them as dependencies into pom.xml
. Maybe this plugin could store them somewhere in ~/.m2/temp/
...
Upvotes: 12
Views: 4537
Reputation: 99
I think the below answer will help you...just place jar files on your SVN and tell them all to e synch with SVN and here the ${lib.directory} will be t he local path
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>db2jcc9</id>
<phase>compile</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>com.ibm</groupId>
<artifactId>db2jcc</artifactId>
<version>9</version>
<packaging>jar</packaging>
<file>${lib.directory}\db2jcc-9.jar</file>
</configuration>
</execution>
</executions>
<plugin>
Upvotes: 0
Reputation: 1816
Yes. This (using non-Mavenized dependencies) is supported by the maven-external-dependency-plugin.
Example:
<artifactItem>
<groupId>jwbroek.cuelib</groupId>
<artifactId>cuelib</artifactId>
<version>${cuelib-version}</version>
<packaging>jar</packaging>
<downloadUrl>http://cuelib.googlecode.com/files/cuelib-${cuelib-version}.jar</downloadUrl>
<checksum>d03b6b960b3b83a2a419e8b5f07b6ba4bd18387b</checksum>
</artifactItem>
It can also extract artifacts from zip files:
<artifactItem>
<groupId>mediautil</groupId>
<artifactId>mediautil</artifactId>
<version>${mediautil-version}</version>
<packaging>jar</packaging>
<install>true</install>
<force>false</force>
<downloadUrl>http://downloads.sourceforge.net/project/mediachest/MediaUtil/Version%201.0/mediautil-1.zip</downloadUrl>
<checksum>aa7ae51bb24a9268a8e57c6afe478c4293f84fda</checksum>
<extractFile>mediautil-${mediautil-version}/mediautil-${mediautil-version}.jar</extractFile>
<extractFileChecksum>e843cd55def75dce57123c79b7f36caca4841466</extractFileChecksum>
</artifactItem>
Upvotes: 6
Reputation: 20777
Here's a different approach that'll let add a Maven repository inside the project directory, use that as a repository in you pom.xml
, and share the repository on SVN with anyone checking out the project. Crosspost from here.
In your project directory, create a folder called repo
, which we'll use as a folder based Maven repository.
Add the following file repository to your project pom.xml
:
<repositories>
<repository>
<id>file.repo</id>
<url>file://${project.basedir}/repo</url>
</repository>
</repositories>
Deploy the external jar(s) to the file repository with the following command:
mvn deploy:deploy-file
-Durl=file:///absolute/path/to/your-project/repo \
-DrepositoryId=file.repo \
-Dfile=path-to-your.jar \
-DgroupId=some.external.project.group \
-DartifactId=the-artifact-name \
-Dversion=1.0 \
-Dpackaging=jar;
Following this you can just add a normal dependency on the jar in your project pom.xml
, using the values for groupId, artifactId and version you passed above. You can then add the repo folder to SVN, and commit the changes to your pom.xml
. Any developer checking out your project will now be able to use the same dependency without any effort.
Upvotes: 0
Reputation: 3394
Taking that your example Dresden OCL has over 20 JAR files, and you need to distribute it to many developers, the best solution would be to install a repository manager somewhere (like nexus or artifactory), take your time to upload these 20 jars to that repository, and use them. Best bet would be to put them in a private groupId, so if they'll get published to a m2 repo sometime, you won't end up with name conflicts.
Another point, would be to ask the Dresden OCL Maintainers, if they can offer a m2 repository. Now that m2eclipse is an eclipse incubator project, this might interest more people.
Upvotes: 2
Reputation: 3749
"mvn install:install-file" mentioned here will help you to install the jars into your local repository. However, if you want to make these jars subsequently available to the developers on the project automaticall, copy the relevant pieces to a repository available to everybody on the project and make this repository available using the tag, for example by checking all the files into the SVN. See http://code.google.com/p/codebistro/wiki/BuildNumber#Maven_Plugin_Example which refers to a SVN-hosted repository for example.
P.S. Have a safe trip to the SV!
Upvotes: 0
Reputation: 16035
You can use "system"-scope in your pom.xml for local library dependencies:
system
This scope is similar to provided except that you have to provide the JAR which contains it explicitly. The artifact is always available and is not looked up in a repository.systemPath
is used only if the the dependency scope is system. Otherwise, the build will fail if this element is set. The path must be absolute, so it is recommended to use a property to specify the machine-specific path (more on properties below), such as ${java.home}/lib. Since it is assumed that system scope dependencies are installed a priori, Maven will not check the repositories for the project, but instead checks to ensure that the file exists. If not, Maven will fail the build and suggest that you download and install it manually.
<dependency>
<groupId>some.id</groupId>
<artifactId>artifact</artifactId>
<version>1.2.3</version>
<scope>system</scope>
<systemPath>${basedir}/path/to/jarFile.jar</systemPath>
</dependency>
AFAIK, you can use pretty much what you want for groupId, artifactId and version. See Maven System Depencies and this question.
Upvotes: 2
Reputation: 4537
You can install it local or deploy it to your site-local (e.g. company-wide) repository. If you use a dependency maven cannot find in the configured repositories, it even gives you the required commands:
Then, install it using the command: mvn install:install-file -DgroupId=mygid -DartifactId=myaid -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there: mvn deploy:deploy-file -DgroupId=mygid -DartifactId=myaid -Dversion=1.0 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Please note: This way you only add the .jar to your repository, there will be no pom along with it to specify transient dependencies. So if your third-party library has dependencies of it's own you'll have to add them manually to your pom.xml as there will be no automatic resolution.
Upvotes: 0
Reputation: 11317
yes you can install it into your local repository with maven-install plugin
mvn install:install-file -Dfile=your-artifact-1.0.jar \
-DgroupId=org.some.group \
-DartifactId=your-artifact \
-Dversion=1.0 \
-Dpackaging=jar \
-DgeneratePom=true
If you want your other team members to be able to download this dependency without having to install it them thelves, you need to setup your own artifact repo, and deploy the artifact there with maven-deploy-plugin in same way as you installed it localy.
Upvotes: 12