將本地jar包打包到本地倉庫而後再引用:web
mvn install:install-file -Dfile=my-jar.jar -DgroupId=org.richard -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar
這裏須要本身改動的有三個地方:apache
-Dfile=my-jar.jar
這裏的-Dfile
屬性指明所要打包的jar包的本地位置;-DgroupId=org.richard
這裏-DgroupId
指明的是打包到本地倉庫的位置,這裏就是打包到org–>richard,而後-DartifactId=my-jar再次指明下一級目錄爲–>my-jar;-Dversion=1.0
經過版本號指定最後一級目錄–>1.0;最後jar包的倉庫位置目錄結構就爲:org–>richard–>my-jar–>1.0–>my-jar.jar,最後的jar名字就是DartifactId-Dversion.jar
的形式maven
使用system scope,svg
<dependencies> <dependency> <!--這裏的屬性本身隨意指定--> <groupId>org.richard</groupId> <artifactId>my-jar</artifactId> <version>1.0</version> <scope>system</scope> <!--將jar包放在項目根目錄下lib(新建)文件中--> <systemPath>${project.basedir}/lib/my-jar.jar</systemPath> </dependency> </dependencies>
而後在pom中新建一個插件便可:測試
<build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-shade-plugin</artifactId> <executions> <execution> <id>make-assembly</id> <phase>package</phase> <goals> <goal>shade</goal> </goals> <configuration> <descriptorRefs> <descriptorRef>jar-with-dependencies</descriptorRef> </descriptorRefs> <finalName>xxx-jar-with-dependencies</finalName> </configuration> </execution> </executions> </plugin> </plugins> <resources> <resource> <targetPath>lib/</targetPath> <directory>lib/</directory> <includes> <include>**/my-jar.jar</include> </includes> </resource> </resources> </build>
最後,因爲最近老是接觸多模塊的Maven項目,之間會有一些依賴,IDEA自帶的打包一些報錯,不知道爲何,只能直接在Dos或Bash下進入Module根目錄進行手動打包而後發版,手動打包(跳過Maven的測試環節):ui
mvn clean -DskipTests install