在Maven项目中使用本地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打包时将不会被包含,可以使用resources将本地包打进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中,将会包含lib目录以及my-jar.jar,并且能够被在执行的时候被找到。
2、将jar包安装到本地repository中
先下载jar包,下载后使用Maven进行本地安装,安装命令如下:
mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging> mvn install:install-file -Dfile=jar包的位置 -DgroupId=上面的groupId -DartifactId=上面的artifactId -Dversion=上面的version -Dpackaging=jar mvn install:install-file -Dfile=D:\XXX.jar -DgroupId=org.springframework -DartifactId=spring-context-support -Dversion=3.1.0.RELEASE -Dpackaging=jar
安装实例参见:http://blog.csdn.net/u014079773/article/details/60773287
参考:http://www.cnblogs.com/richard-jing/archive/2013/01/27/Maven_localjar.html
时间: 2024-10-12 17:43:50