Maven項目中使用本地JAR包方案3

因爲有些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

相關文章
相關標籤/搜索