Where to put a JAR

90 views
Skip to first unread message

David Pollak

unread,
Mar 2, 2008, 9:42:35 PM3/2/08
to liftweb
Folks,

I've got a JAR file that I want to access and it's not in the maven repository.  Where can I put the JAR in my project such that it's found during an Maven compile/install?

Thanks,

David

PS src/main/webapp/WEB-INF/lib didn't work


--
lift, the secure, simple, powerful web framework http://liftweb.net
Collaborative Task Management http://much4.us

Viktor Klang

unread,
Mar 2, 2008, 9:46:32 PM3/2/08
to lif...@googlegroups.com
Hey Dave,

You could manually add it into the POM and the import it into your mave repo using the "mvn install:install-file" command

Cheers,
-V
--
_____________________________________
/                                                                 \
       /lift/ committer (www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/

David Pollak

unread,
Mar 2, 2008, 11:03:07 PM3/2/08
to lif...@googlegroups.com
On 3/2/08, Viktor Klang <viktor...@gmail.com> wrote:
Hey Dave,

You could manually add it into the POM and the import it into your mave repo using the "mvn install:install-file" command

Except then it wouldn't build on anyone else's machine. 

Cheers,
-V


On Mon, Mar 3, 2008 at 3:42 AM, David Pollak <feeder.of...@gmail.com> wrote:
Folks,

I've got a JAR file that I want to access and it's not in the maven repository.  Where can I put the JAR in my project such that it's found during an Maven compile/install?

Thanks,

David

PS src/main/webapp/WEB-INF/lib didn't work


--
lift, the secure, simple, powerful web framework http://liftweb.net
Collaborative Task Management http://much4.us




--
_____________________________________
/                                                                 \
       /lift/ committer (www.liftweb.net)
     SGS member (Scala Group Sweden)
 SEJUG member (Swedish Java User Group)
\_____________________________________/

Steve Jenson

unread,
Mar 2, 2008, 11:29:57 PM3/2/08
to lif...@googlegroups.com
I do this on my project currently with a jar. I have the other
developer mvn install:install-file it as well. It's one command and,
sadly, is the best I could come up with.

You just have to remember to install-file it again if you wipe out ~/.m2.

There must be a better way, I would imagine.

Steve

Brendan Grainger

unread,
Mar 2, 2008, 11:46:53 PM3/2/08
to lif...@googlegroups.com
Hi David,

Does this help:

    <dependency>
      <groupId>whatever.you.want.to.call.it</groupId>
      <artifactId>whatever.you.want.to.call.it</artifactId>
      <version>1.0-SNAPSHOT</version>
      <scope>system</scope>
      <!-- personally I normally just have a lib dir for this, but you might want to make it
${basedir}/src/main/webapp/WEB-INF/lib -->
      <systemPath>${basedir}/path/to/your/jar/jar_name.jar</systemPath>
    </dependency>

Regards
Brendan

David Pollak

unread,
Mar 3, 2008, 12:53:20 AM3/3/08
to lif...@googlegroups.com
Worked like a charm!

Thanks!

David Bernard

unread,
Mar 3, 2008, 3:44:31 AM3/3/08
to lif...@googlegroups.com
Brendan Grainger provide one of the solution (the simple).
Personnally I prefer an other one (longuer but cleaner in my opinion) : using an embedded repository.
1/ create the repository
mkdir -p myproject/repo-embedded/
2/ copy the jar into the repository
2.1/ could be done manually
mkdir -p myproject/repo-embedded/<groupId/of/the/jar>/<artifactId>/<version>
cp thelib.jar myproject/repo-embedded/<groupId/of/the/jar>/<artifactId>/<version>/artifactId-version.jar
cat >> myproject/repo-embedded/<groupId/of/the/jar>/<artifactId>/<version>/artifactId-version.pom <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>*groupId*</groupId>
<artifactId>*artifactId*</artifactId>
<version>*version*</version>
<packaging>jar</packaging>
</project>
EOF
2.2/ or use the maven plugin
mvn install:install-file -DlocalRepositoryPath=myproject/repo-embedded \
-Dfile=thelib.jar \
[-DpomFile=your-pom.xml] \
[-Dversion=1.0] \
-DgroupId=org.some.group \
-DartifactId=your-artifact
2.3/ or copy from an existing repository (your local or a private)
3/ declare the embedded repository in your pom.xml
<repositories>
<repository>
<id>embedded</id>
<name>Project Embbed Repository</name>
<url>file://${basedir}/repo-embedded</url>
<snapshots />
<releases />
</repository>
</repositories>
4/ use this lib like any other lib

I agree it is lot of more work (the first time), but there is some advantages :
* you could define the exact scope for the lib in your pom (compile, test, runtime, provided)
* if the lib has dependencies, you could create a custom pom for the lib with its dependencies without the need to pollute your project's pom.xml with its dependencies
* you could add information to the lib (name, url,...) => shown in the dependencies report of your project


Notes:
* both solutions (embedded repo and system scope) should only be used for application (or lib) that you don't plan to deploy to a repository, else when user will download your stuff from the repo
there will be missing dependencies. (=> ok for war, and for dependencies in provided/test scope)
* for the full list of option of "mvn install:install-file", see http://maven.apache.org/plugins/maven-install-plugin/install-file-mojo.html#localRepositoryPath

/davidB

David Pollak wrote:
> Worked like a charm!
>
> Thanks!
>
> Brendan Grainger wrote:
>> Hi David,
>>
>> Does this help:
>>

>> * **<**dependency**>*
>> * **<**groupId**>**whatever.you.want.to.call.it**</**groupId**>*
>> *
>> **<**artifactId**>**whatever.you.want.to.call.it**</**artifactId**>*
>> * **<**version**>**1.0-SNAPSHOT**</**version**>*
>> * <scope>system</scope>*
>> * <!-- personally I normally just have a lib dir for this, but
>> you might want to make it*
>> * **${basedir}/s**rc/main/webapp/WEB-INF/lib -->*
>> * <systemPath>${basedir}/path/to/your/jar/jar_name.jar</systemPath>*
>> * **</**dependency**>*


>>
>> Regards
>> Brendan
>>
>>
>> On Mar 2, 2008, at 11:29 PM, Steve Jenson wrote:
>>
>>>
>>> I do this on my project currently with a jar. I have the other
>>> developer mvn install:install-file it as well. It's one command and,
>>> sadly, is the best I could come up with.
>>>
>>> You just have to remember to install-file it again if you wipe out ~/.m2.
>>>
>>> There must be a better way, I would imagine.
>>>
>>> Steve
>>>
>>> On Sun, Mar 2, 2008 at 8:03 PM, David Pollak
>>> <feeder.of...@gmail.com

>>> <mailto:feeder.of...@gmail.com>> wrote:
>>>>
>>>>
>>>>
>>>> On 3/2/08, Viktor Klang <viktor...@gmail.com

>>>> <mailto:viktor...@gmail.com>> wrote:
>>>>> Hey Dave,
>>>>>
>>>>> You could manually add it into the POM and the import it into your mave
>>>> repo using the "mvn install:install-file" command
>>>>
>>>> Except then it wouldn't build on anyone else's machine.
>>>>
>>>>> Cheers,
>>>>> -V
>>>>>
>>>>>
>>>>>
>>>>> On Mon, Mar 3, 2008 at 3:42 AM, David Pollak
>>>> <feeder.of...@gmail.com

>>>> <mailto:feeder.of...@gmail.com>> wrote:
>>>>>
>>>>>> Folks,
>>>>>>
>>>>>> I've got a JAR file that I want to access and it's not in the maven
>>>> repository. Where can I put the JAR in my project such that it's found
>>>> during an Maven compile/install?
>>>>>>
>>>>>> Thanks,
>>>>>>
>>>>>> David
>>>>>>
>>>>>> PS src/main/webapp/WEB-INF/lib didn't work
>>>>>>
>>>>>>
>>>>>> --
>>>>>> lift, the secure, simple, powerful web framework http://liftweb.net
>>>>>> Collaborative Task Management http://much4.us
>>>>>>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> _____________________________________
>>>>> / \

>>>>> /lift/ committer (www.liftweb.net <http://www.liftweb.net>)

Reply all
Reply to author
Forward
0 new messages