Maven项目中使用本地JAR包
来源:互联网 发布:女朋友说我不懂她 知乎 编辑:程序博客网 时间:2024/04/30 21:24
在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,并且能够被在执行的时候被找到。
有的时候这种方法会实效,比如JDBCDriver在声明的时候Class.forName("xxx.Driver")就会说找不到类,用下面两种方法就可以。
2. 将jar包安装到本地repository中
mvn install:install-file -Dfile=my-jar.jar -DgroupId=org.richard -DartifactId=my-jar -Dversion=1.0 -Dpackaging=jar
3. 添加 in project repository,在新机器上执行时就不用运行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包及路径必须严格遵循格式:
/groupId/artifactId/version/artifactId-verion.jar
本例中: lib/org/richard/my-jar/1.0/my-jar-1.0.jar
0 0
- Maven项目中使用本地JAR包
- Maven项目中使用本地JAR包
- Maven项目中使用本地JAR包
- Maven项目中使用本地JAR包
- Maven项目中使用本地JAR包
- Maven项目中使用本地JAR包
- Maven项目中使用本地JAR包
- 在Maven项目中使用本地JAR包
- maven项目中添加本地jar包
- maven项目使用本地jar包
- Maven中使用本地JAR包
- 在 maven 中使用本地 jar 包
- Maven中使用本地JAR包
- Maven中使用本地JAR包
- Maven中使用本地JAR包
- Maven 中使用本地 jar 包
- Maven使用本地jar包
- Maven 使用本地 jar包
- fragment的使用以及fragment大家族解析
- PYTHON黑帽编程1.5 使用WIRESHARK练习网络协议分析
- 图片防盗链
- ROS by example -第十二章 DYNAMIXEL 伺服系统和 ROS
- UVA1225 UVALive3996 Digit Counting
- Maven项目中使用本地JAR包
- Activiti介绍
- Trie树的DAT实现
- Spring依赖注入详解
- SELinux 的启动、关闭与查看
- MongoDB和MongoDB云数据库浅谈
- 优酷的菜单
- C++重载、覆盖、隐藏
- 直播当中的装饰品