If a JAR library has to be included in the project's source code, it useful to create a directory repository next to the project's source code to store the library.
Deploying a library from the source code
Maven allows to redirect the target of the deploy
command into a directory.
repositoryDir=some-dir
mvn clean deploy -DaltDeploymentRepository=snapshot-repo::default::file:${repositoryDir}
Installing an existing JAR-packaged library
For existing JAR files, Maven provides install plugin which allows to deploy existing JAR package to a directory repository. If you have a POM file, for the file, you will have to gather following information about your package.
groupId: com.microsoft.sqlserver
artifactId: sqljdbc4
version: 4.2
Then just execute follwing command and Maven will create aprropriate directory structure, copy and rename the JAR file and generate POM file.
mvn install:install-file \
-Dfile=sqljdbc4.jar \
-DgroupId=com.microsoft.sqlserver \
-DartifactId=sqljdbc4 \
-Dversion=4.2 \
-Dpackaging=jar \
-DlocalRepositoryPath=${repositoryDir}
You should end up with following structure.
<repositoryDir>/com/microsoft/sqlserver/sqljdbc4/4.2/sqljdbc4-4.2.jar
<repositoryDir>/com/microsoft/sqlserver/sqljdbc4/4.2/sqljdbc4-4.2.pom
Using a directory repository in a project
By adding a directory repository into your project, Maven will look for library files in that directory. In case of, you are working with multi-module builds, put the repositories
definition into the parent project's pom file.
-
Define a path to directory repository.
<repositories> <repository> <id>Project repository</id> <url>file://${basedir}/<repositoryDir></url> </repository> </repositories>
-
Use the library as any other dependency.
<dependencies> <dependency> <groupId>com.microsoft.sqlserver</groupId> <artifactId>sqljdbc4</artifactId> <version>4.2</version> </dependency> </dependencies>