Maven: How to enable banks that are not available in repetitions in a J2EE project?

in my J2EE project I have a couple of dependencies that are not available in any Maven repository because they are native libraries. These libraries must be accessible at run time, so they must be copied to the target /.../ WEB-INF / lib ...

I am currently listing them as a system dependency in my POM, but with this method there is a problem that is not copied to the target assembly at compile time. Also this method is not very elegant.

So what is the best way to integrate them into Maven?

Note. I do not want to create my own Maven repository.

+96
java maven-2 build-process
Jul 22 '09 at 9:14
source share
11 answers

As you said, you do not want to set up your own repository, perhaps this will help.

You can use the installation file in maven-install-plugin to install the file in the local repository. If you create a script with a Maven call for each file and keep it near the banks, you (and everyone with access) can easily install the banks (and the associated pom files) in their local repository.

For example:

mvn install:install-file -Dfile=/usr/jars/foo.jar -DpomFile=/usr/jars/foo.pom mvn install:install-file -Dfile=/usr/jars/bar.jar -DpomFile=/usr/jars/bar.pom 

or simply

 mvn install:install-file -Dfile=ojdbc14.jar -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0 -Dpackaging=jar 

You can then reference the dependencies as usual in your project.

However, it is best to set up an internal remote repository, and I would recommend using Nexus . It can be launched in your development window, if necessary, and the overhead is minimal.

+53
Jul 22. '09 at 11:07
source share

For people who want to quickly solve this problem:

 <dependency> <groupId>LIB_NAME</groupId> <artifactId>LIB_NAME</artifactId> <version>1.0.0</version> <scope>system</scope> <systemPath>${basedir}/WebContent/WEB-INF/lib/YOUR_LIB.jar</systemPath> </dependency> 

just give the library a unique groupID and artifact and indicate where it is in the file system. You will go well.

Of course, this is a dirty quick solution that will ONLY work on your computer and if you do not change the path to the libraries. But a few times, all you want is to run and do some tests.

EDIT: just reinstall the question and realized that the user has already used my solution as a temporary fix. I will leave my answer as a quick help to others who come to this question. If someone does not agree with this, leave me a comment. :)

+187
Oct 31 '12 at 15:05
source share

Create a repository folder in your project. Let’s take

 ${project.basedir}/src/main/resources/repo 

Then install your custom jar in this repo:

 mvn install:install-file -Dfile=[FILE_PATH] \ -DgroupId=[GROUP] -DartifactId=[ARTIFACT] -Dversion=[VERS] \ -Dpackaging=jar -DlocalRepositoryPath=[REPO_DIR] 

Finally, add the following repo and dependency definitions to your pom.xml projects:

 <repositories> <repository> <id>project-repo</id> <url>file://${project.basedir}/src/main/resources/repo</url> </repository> </repositories> <dependencies> <dependency> <groupId>[GROUP]</groupId> <artifactId>[ARTIFACT]</artifactId> <version>[VERS]</version> </dependency> </dependencies> 
+23
Dec 11 '15 at 9:22
source share

You need to set up a local repository that will host these libraries. There are a number of projects that do just that. For example Artifactory .

+8
Jul 22 '09 at 9:44
source share

None of the solutions work if you use the Jenkins build! When pom starts inside the Jenkins build server .. these solutions will fail because Jenkins run pom will try to download these files from the corporate repository.

Copy jars under src / main / resources / lib (create the lib folder). They will be part of your project and will go fully to the deployment server. On the deployment server, make sure your startup scripts contain src / main / resources / lib / * in the classpath. Viola.

+3
Jul 20 '16 at 23:29
source share

you can install them in a private local repository (for example, .m2 / repository under your home directory): more here

+2
Jul 22 '09 at 9:22
source share

If I understand well what you want to do is export the dependencies during the compilation phase, so there is no need to manually extract each required library, you can use mojo copy-dependencies .

Hope this can be useful in your case ( examples )

+2
Jul 22 '09 at 10:21
source share

Continue to use them as a system dependency and copy them to the target /.../ WEB-INF / lib ... using the Maven dependency plugin:

http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html

+1
Jul 22 '09 at 12:04
source share

Only one installation did not work for me.

 mvn deploy:deploy-file -Durl=file:///home/me/project/lib/ \ -Dfile=target/jzmq-2.1.3-SNAPSHOT.jar -DgroupId=org.zeromq \ -DartifactId=zeromq -Dpackaging=jar -Dversion=2.1.3 
+1
Apr 04 '13 at 1:04 on
source share

@Ric Jafe's solution is what worked for me.

This is exactly what I was looking for. A way to push it for a research code. Nothing special. Yes, I know what they all say :) Various solutions for maven plugins seem redundant for my purposes. I have several cans that were provided to me as third-party libraries with a pom file. I want it to compile / execute quickly. This decision, which I trivially adapted to the python, worked wonders on me. Cut and paste in my pom. The Python / Perl code for this task is in this Q & A: Can I add banks to the maven 2 build classpath without installing them?

 def AddJars(jarList): s1 = '' for elem in jarList: s1+= """ <dependency> <groupId>local.dummy</groupId> <artifactId>%s</artifactId> <version>0.0.1</version> <scope>system</scope> <systemPath>${project.basedir}/manual_jars/%s</systemPath> </dependency>\n"""%(elem, elem) return s1 
+1
Feb 12
source share

You can try using maven-external-dependency-plugin, which shows a good way to add external jars to any Maven project.

https://code.google.com/p/maven-external-dependency-plugin/

0
Oct 10 '14 at 3:33
source share



All Articles