Maven中使用本地JAR包
為什么80%的碼農(nóng)都做不了架構(gòu)師?>>> ??
在Maven項(xiàng)目中使用本地JAR包有兩種方法: 1、使用system scope
<dependencies><dependency><groupId>org.richard</groupId><artifactId>my-jar</artifactId><version>1.0</version><scope>system</scope><systemPath>${project.basedir}/lib/my-jar.jar</systemPath></dependency></dependencies>system scope引入的包,在使用jar-with-dependencies打包時(shí)將不會(huì)被包含,可以使用resources將本地包打進(jìn)jar-with-dependencies
<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>生成的xxx-jar-with-dependencies.jar中,將會(huì)包含lib目錄以及my-jar.jar,并且能夠被在執(zhí)行的時(shí)候被找到。 有的時(shí)候這種方法會(huì)實(shí)效,比如JDBCDriver在聲明的時(shí)候Class.forName("xxx.Driver")就會(huì)說(shuō)找不到類(lèi),用下面兩種方法就可以。
2、將jar包安裝到本地repository中
mvn install:install-file -Dfile=my-jar.jar -DgroupId=org.richard -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar3、添加?in project repository,在新機(jī)器上執(zhí)行時(shí)就不用運(yùn)行mvn install:install-file命令了
<repository><id>in-project</id><name>In Project Repo</name><url>file://${project.basedir}/lib</url> </repository><dependency><groupId>org.richard</groupId><artifactId>my-jar</artifactId><version>1.0</version> </dependency>你的jar包及路徑必須嚴(yán)格遵循格式:
/groupId/artifactId/version/artifactId-verion.jar本例中: lib/org/richard/my-jar/1.0/my-jar-1.0.jar
轉(zhuǎn)載于:https://my.oschina.net/dabird/blog/645636
創(chuàng)作挑戰(zhàn)賽新人創(chuàng)作獎(jiǎng)勵(lì)來(lái)咯,堅(jiān)持創(chuàng)作打卡瓜分現(xiàn)金大獎(jiǎng)總結(jié)
以上是生活随笔為你收集整理的Maven中使用本地JAR包的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【数据结构与算法】【算法思想】拓扑排序
- 下一篇: [密码学基础][每个信息安全博士生应该知