tags:

views:

70

answers:

2

I'm just starting with maven, coming from years of working with Ant. I'm trying a basic task now, building a simple project that requires some libraries from a vendor. I have the jars in src\main\resources\VENDORNAME. When I run mvn compile it fails on compilation saying the libraries don't exist. I can't seem to add these as dependencies because I don't know their version number and as they are proprietary I can't find them in ibiblio or elsewhere. Without these Jars I can't compile my classes.
Is there a way to use jars that didn't follow Maven's convention? I might not understand maven correctly, so any guidance is welcome. Much appreciated for any responses.

+2  A: 

I would write your own POM file for these jars and add them to your repository. Doesn't have to be anything fancy, just a bare-bones POM file. That way you can include them without breaking "The Maven Way".

If you want Maven to automatically generate one for you, and install it to your local repo, you can use this command:

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> \
    -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>
dbyrne
Thanks for the advice, what could I use for the version number of these? I have no access to the source code so i can't build the jars myself.
JasonH
In cases where a version number either does not exist or I have no way of finding it out, I just label it 1.0.
dbyrne
Thanks for the help, I appreciate it.
JasonH
A: 

Putting the external non-mavenized dependencies into a repository is really the best way - you & others can reuse them on other projects etc. However if this isn't feasible, you can also reference a dependency stored on the disk (perhaps checked out from your version control system as in those old, ugly pre-maven ages). Here is an example of a POM referencing a JAR stored in the project's lib/ folder:

<project ...>
...
        <dependency>
            <groupId>com.ascentialsoftware</groupId>
            <artifactId>tr4j</artifactId>
            <version>8.1</version>
            <scope>system</scope>
            <systemPath>${basedir}/lib/tr4j.jar</systemPath>
        </dependency>
...
</project>

ehm, I've only now noticed that this solution is in the answer to "Maven: add a dependency to a jar by relative path", which is linked to this post - you should check it for a more in-depth discussion. However I leave this here as it's more visible than the link.

Jakub Holý
Thanks Jakub, I still have to do the mvn install though for each jar though don't I? I think I'm understanding the concept, but doing this for 200 jars is quite a pain, I'd like to see something like Ivy's flat repository that doesn't require the install step...
JasonH