因为有些Jar包不是开源的,在maven remote repositories找不到相应的包,因此得经过自有的Jar包在local repositories中添加jar。而后在pom.xml中添加相应的dependency,就能用本地的jar了。
首先,在本地在添加Jar,它的格式为:java
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
下面是一个真实的例子:bash
mvn install:install-file -Dfile=fastdfs-client-java-1.25.jar -DgroupId=org.csource -DartifactId=fastdfs-client-java -Dversion=1.25 -Dpackaging=jar
执行后jar文件会自动加入本地库中,经过如下方式引用是正常的。maven
<dependency> <groupId>org.csource</groupId> <artifactId>fastdfs-client-java</artifactId> <version>1.25</version> </dependency>
可是这样有一个问题,就是其余同事也要运行一下这个方法才行,否则可能没法使用相应的jar文件。code