пятница, 13 июля 2012 г.

Maven - add custom jar to maven project

...based on (http://blog.dub.podval.org/2010/01/maven-in-project-repository.html)

In this example I will add custom log4j-1.2.1234.jar to my project

1. Create folder with name lib in project root (where pom.xml is placed)

2. Add next structure to pom.xml

<repositories>
    < repository>
         < id > lib < /id>
        < name > lib < /name>
         < releases>
            < enabled > true < /enabled >
             < checksumPolicy > ignore < /checksumPolicy>
         < /releases>
         < snapshots>
             < enabled > false < /enabled>
         < /snapshots >
         < url > file://${project.basedir}/lib < /url>
     < /repository>
  < /repositories>



3. Then install necessary jar (log4j-1.2.1234.jar) to local maven repo:

mvn install:install-file -Dfile=log4j-1.2.1234.jar -DgroupId=myrepo -DartifactId=log4j -Dversion=1.2.1234 -Dpackaging=jar

4. Then go to $user_home/.m2/repository/myrepo/log4j/1.2.1234/ and copy all it contents to {$project root}/lib/myrepo/log4j/1.2.1234/

5. Add new dependency jar to project:


          < dependency >
             < groupId > myrepo < /groupId >
             < artifactId > log4j < /artifactId>
            < version > 1.2.1234 < /version>
         < /dependency >


That's all.


PS. Every time you compile this project on new machine jar's will be added to local maven repo of this new machine

Комментариев нет:

Отправить комментарий