Adding project local libraries to maven

Before moving to maven our libraries were kept in the project lib directory and shared through version control. Now we have moved to using maven I can find all my dependencies from the maven repositories.

However I have found out that it can be sometimes handy to still use the old approach for those special dependencies, especially if you don't have a repository setup in your local network. So we have a dependency for old-stuff.jar which is in the lib directory in our new-fantastic maven project.

 Directory of new-fantastic

[.]       [..]      [lib]     pom.xml   [src]               

 Directory of new-fantastic\lib

[.]             [..]            old-stuff.jar
  1. First we add the lib directory as a repository to the pom.xml
  2.   <repositories>
            <repository>
                <id>local-project-libraries</id>
                <name>Local project libraries</name>
                <url>file://${project.basedir}/lib</url>
                <layout>default</layout>
            </repository>
       </repositories>
    
  3. Then we add a depencency to the old-stuff.jar to the pom.xml
  4.   <dependencies>
        <dependency>
          <groupId>com.blogspot.pragmastic</groupId>
          <artifactId>old-stuff</artifactId>
          <version>0.9</version>
        </dependency>
      </dependencies>
  5. Now if we run maven it will helpfully tell us that the dependency cannot be found and that we should either install it or deploy it to a repository
  6. Missing:
    ----------
    1) com.blogspot.pragmastic:old-stuff:jar:0.9
    
      Try downloading the file manually from the project website.
    
      Then, install it using the command:
          mvn install:install-file -DgroupId=com.blogspot.pragmastic
    -DartifactId=old-stuff -Dversion=0.9 -Dpackaging=jar -Dfile=/path/to/file
    
      Alternatively, if you host your own repository you can deploy the file there:
          mvn deploy:deploy-file -DgroupId=com.blogspot.pragmastic
    -DartifactId=old-stuff -Dversion=0.9 -Dpackaging=jar -Dfile=/path/to/file
    -Durl=[url] -DrepositoryId=[id]
  7. Now we use the command from the message and deploy the file to our Local project libraries repository
  8. mvn deploy:deploy-file -DgroupId=com.blogspot.pragmastic -DartifactId=old-stuff -Dversion=0.9 
    -Dpackaging=jar -Dfile=lib/old-stuff.jar -Durl=file://${project.basedir}/lib 
    -DrepositoryId=local-project-libraries
  9. After this we can run maven and it will load the dependency from our local repository

2 comments:

  1. An alternative (and probably simpler) way to handle this issue is using addjars-maven-plugin ( http://code.google.com/p/addjars-maven-plugin/ )

    ReplyDelete
  2. ainol professional brand website !

    ReplyDelete