Add a jar file to the local Maven library and add a jar file to maven
Sometimes the maven dependency we want to use cannot be found in the official repo library. However, we have obtained all jar files in the dependency from other channels. This article records how to add jar files to the local library.
There are three methods from complexity to Simplicity:
The first method is helpful for team development. I plan to record it with an article. Here we will introduce two other methods:
Run the command mvn install: install-file to install the jar file to the local repository.
Syntax specification:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> -DgeneratePom=true Where: <path-to-file> the path to the file to load <group-id> the group that the file should be registered under <artifact-id> the artifact name for the file <version> the version of the file <packaging> the packaging of the file e.g. jar
Take the document <not-yet-commons-ssl-0.3.17.jar> as an example:
mvn install:install-file -Dfile=e:\not-yet-commons-ssl-0.3.17.jar -DgroupId=org.apache.commons -DartifactId=not-yet-commons-ssl -Dversion=0.3.17 -Dpackaging=jar -DgeneratePom=true
Import data through the project pom configuration file
Edit the project pom file, add an entry to the dependency, and specify <scope> and <systemPath>.
Or the file <not-yet-commons-ssl-0.3.17.jar> as an example:
<dependency> <groupId>org.apache.commons</groupId> <artifactId>not-yet-commons-ssl</artifactId> <version>0.3.17</version> <scope>system</scope> <systemPath>e:\not-yet-commons-ssl-0.3.17.jar</systemPath></dependency>
Wait. A warning is displayed after compilation:
[WARNING] 'dependencies.dependency.systemPath' for org.apache.commons:not-yet-commons-ssl:jar should use a variable instead of a hard-coded path e:\not-yet-commons-ssl-0.3.17.jar @ line 35, column 16
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
It turned out that maven told us not to use absolute paths such as C: \ Windows, but to use $ {java. the relative path (variable) such as home}, otherwise it reduces compilation reproducibility and threatens us to not support this method in the future.
Well, we can create a maven repository environment variable to eliminate this warning if you think it is necessary.