tags:

views:

19842

answers:

9

Maven2 is driving me crazy during the experimentation/quick and dirty mock-up phase of development.

I have a pom.xml file that defines the dependencies for the web-app framework I want to use, and I can quickly generate starter projects from that file. However, sometimes I want to link to a 3rd party library that doesn't already have a pom.xml file defined, so rather than create the pom.xml file for the 3rd party lib by hand and install it, and add the dependency to my pom.xml, I would just like to tell maven: "In addition to my defined dependencies, include any jars that are in /lib too."

It seems like this ought to be simple, but if it is, I am missing something.

Any pointers on how to do this are greatly appreciated. Short of that, if there is a simple way to point maven to a /lib directory and easily create a pom.xml with all the enclosed jars mapped to a single dependency which I could then name/install and link to in one fell swoop would also suffice.

Thanks!

A: 

This doesn't answer how to add them to your POM, and may be a no brainer, but would just adding the lib dir to your classpath work? I know that is what I do when I need an external jar that I don't want to add to my Maven repos.

Hope this helps.

javamonkey79
This is what I was doing, and it works, but it also pollutes the global class path, and I'm trying to get away from it. Thanks!
+30  A: 

set scope == system and just make up a groupId, artifactId, and version

<dependency>
    <groupId>org.swinglabs</groupId>
    <artifactId>swingx</artifactId>
    <version>0.9.2</version>
    <scope>system</scope>
    <systemPath>path to ... swingx-0.9.3.jar</systemPath>
</dependency>
Pyrolistical
Thanks this is really close to what I want. Any way to add them all as a single entry? Say I have /lib with 10 jars, can I add them all somehow, for instance with /some/path/*.jar for the systemPath? or I still have to treat each as a known dependency?Still, really close to what I need, thanks!
I don't know of a way to do it by a group of jars, just do it this way, its more consistent
Pyrolistical
use a systemPath like this one: "<systemPath>${basedir}/lib/BrowserLauncher2-1_3.jar</systemPath>" ${basedir} is pointing to your project's root.
Frederic Morin
+1, but can you explain a little more about scope "system" ?
Leonel
Scope system means that you must indicate to Maven2 where the library must be found (specified in systemPath), as the dependency will *not* be found in the local repository of Maven2. This can be usefull when the library is not present in any repository and you don't want to install it.However, the scope system is discouraged!
romaintaz
It is better to use the project. prefix in your path like so: <systemPath>${project.basedir}/lib/AwesomeLib.jar</systemPath>
Matthew McCullough
MatthieuF
While I understand that this is what the OP was asking for, I still want to underline that using a `system` scope is an horrible practice that is **strongly discouraged**. See [Dependency+Scopes](http://docs.codehaus.org/display/MAVENUSER/Dependency+Scopes).
Pascal Thivent
+15  A: 

Note: When using the System scope (as mentioned on this page), Maven needs absolute paths.

If your jars are under your project's root, you'll want to prefix your systemPath values with ${basedir}.

Ed Brannin
+1  A: 

http://maven.apache.org/plugins/maven-install-plugin/usage.html

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).

Jeremy Wilde
actually, what he ment is that you dont have to create a pom for the library you are importing into your local repository
Frederic Morin
-1, sometimes you just want to add a jar file without the trouble of installing it.
Leonel
+5  A: 

You really ought to get a framework in place via a repository and identifying your dependencies up front. Using the system scope is a common mistake people use, because they "don't care about the dependency management." The trouble is that doing this you end up with a perverted maven build that will not show maven in a normal condition. You would be better off following an approach like this.

Brian Fox
A: 

I would like to keep set of property files outside jar being generated through maven. How do i tell maven to add the directory containing these property files to its classpath so that Spring can be able to pick it up. I googled a lot, but couldn't find a solution yet (i don't want to add them as dependency).

you should ask this as a question if you haven't already
Rich Seller
A: 

I would like to keep set of property files outside jar being generated through maven. How do i tell maven to add the directory containing these property files to its classpath so that Spring can be able to pick it up. I googled a lot, but couldn't find a solution yet (i don't want to add them as dependency).

I have the same problem, have you found a solution? thx

Please make it a separate question, as it is not the same problem!
romaintaz
A: 

A strange solution I found:

using Eclipse

  • create simple (non-maven) java project
  • add a Main class
  • add all the jars to the classpath
  • export Runnable JAR (it's important, because no other way here to do it)
  • select Extract required libraries into generated JAR
  • decide the licence issues
  • tadammm...install the generated jar to your m2repo
  • add this single dependency to your other projects.

cheers, Balint

Balint Pato
A: 

Even though it does not exactly fit to your problem, I'll drop this here. My requirements were:

  1. Jars that can not be found in an online maven repository should be in the SVN.
  2. If one developer adds another library, the other developers should not be bothered with manually installing them.
  3. The IDE (NetBeans in my case) should be able find the sources and javadocs to provide autocompletion and help.

Let's talk about (3) first: Just having the jars in a folder and somehow merging them into the final jar will not work for here, since the IDE will not understand this. This means all libraries have to be installed properly. However, I dont want to have everyone installing it using "mvn install-file".

In my project I needed metawidget. Here we go:

  1. Create a new maven project (name it "shared-libs" or something like that).
  2. Download metawidget and extract the zip into src/main/lib.
  3. The folder doc/api contains the javadocs. Create a zip of the content (doc/api/api.zip).
  4. Modify the pom like this http://pastebin.com/GscFtMUP
  5. Build the project and the library will be installed.
  6. Add the library as a dependency to your project, or (if you added the dependency in the shared-libs project) add shared-libs as dependency to get all libraries at once.

Every time you have a new library, just add a new execution and tell everyone to build the project again (you can improve this process with project hierachies).

Arian
You might want to check [Maven: add a dependency to a jar by relative path](http://stackoverflow.com/questions/2229757/maven-add-a-dependency-to-a-jar-by-relative-path/2230464#2230464) (which is IMHO a better alternative).
Pascal Thivent
It is better if you can ensure that the local repository always has the same relative path to the project. If I have many projects (or different branches) in different locations this will not work.
Arian
[My answer](http://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them/426176#426176) has a way to tell pom.xml about a jar inside your project. Why not just do that, and point it to jars in ${basedir}/lib?
Ed Brannin
@Ed Because that's absolutely not what the system scope is for, system scoped dependencies have lots of side effects. This is an horrible practice that should be totally banned.
Pascal Thivent