Adding Custom Jar as Maven Dependency
Using maven in a Java project is good. But sometimes, you use a handmake custom jar, your library used that has a bug and you make a quick fix, ... and they are not exist on public maven repository. Here some solutions
Install jar by using install-plugin
Store the jar into a project directory and install it into the m2repo directory. Using
maven-install-plugin
<plugins> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> <executions> <execution> <id>install_1</id> <phase>initialize</phase> <goals> <goal>install-file</goal> </goals> <configuration> <groupId>com.coloza</groupId> <artifactId>custom-1</artifactId> <version>1.0</version> <packaging>jar</packaging> <file>${basedir}/lib/custom-1.jar</file> </configuration> </execution> <execution> <id>install_2</id> <phase>initialize</phase> <goals> <goal>install-file</goal> </goals> <configuration> <groupId>com.coloza</groupId> <artifactId>custom-2</artifactId> <version>1.0</version> <packaging>jar</packaging> <file>${basedir}/lib/custom-2.jar</file> </configuration> </execution> </executions> </plugin> <plugins> <dependencies> <dependency> <groupId>com.coloza</groupId> <artifactId>custom-1</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>com.coloza</groupId> <artifactId>custom-2</artifactId> <version>1.0</version> </dependency> </dependencies>
Creating maven repo inside the project
Create maven repo that runs on our own computer instead or a remote server. Every file needed would be on the version control system so every developer can build the project once it is downloaded
Add the local repository to the project pom
<repositories> <repository> <id>project.local</id> <name>Local Repository</name> <url>file://${basedir}/local-repo</url> <!-- repository will be stored in “local-repo” directory and located at root of project directory --> </repository> </repositories>
Install jar in the repository through install-plugin
mvn install:install-file -Dfile=
-DgroupId= -DartifactId= \ -Dversion= -Dpackaging= -DlocalRepositoryPath= Example
mvn install:install-file -Dfile=D:/downloads/custom.jar -DgroupId=com.coloza \ -DartifactId=custom -Dversion=1.0 -Dpackaging=jar -DlocalRepositoryPath=local-repo
There are several options to be filled on the command:
path-to-artifact-jar
: the path to the file of the artifact to installgroupId
,artifactId
,version
: the group, artifact name and version of the artifact to installpackaging
: the packaging of the artifact (jar)path-to-specific-local-repo
: the path to the local repo
Add the dependency to the project
<dependencies> <dependency> <groupId>groupId</groupId> <artifactId>artifactId</artifactId> <version>version</version> </dependency> </dependencies>
Comments
Post a Comment