如何将本地jar文件(还不是Maven存储库的一部分)直接添加到项目的库源中?
当前回答
真正快速而肮脏的方法是指向本地文件,请注意“system”现在已被弃用:
<dependency>
<groupId>com.sample</groupId>
<artifactId>samplifact</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>C:\DEV\myfunnylib\yourJar.jar</systemPath>
</dependency>
然而,这只会存在于您的机器上(显然),因为共享通常使用适当的m2存档(nexus/artifactory)是有意义的,或者如果您没有这些存档或不想设置本地maven结构化存档并在pom中配置“存储库”:
本地:
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://C:/DEV//mymvnrepo</url>
</repository>
</repositories>
远程:
<repositories>
<repository>
<id>my-remote-repo</id>
<url>http://192.168.0.1/whatever/mavenserver/youwant/repo</url>
</repository>
</repositories>
对于此解决方案,还可以使用basedir变量创建相对路径:
<url>file:${basedir}</url>
其他回答
依赖关系的重要部分是:${pom.basedir}(而不仅仅是${basedir})
<dependency>
<groupId>org.example</groupId>
<artifactId>example</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${pom.basedir}/src/lib/example.jar</systemPath>
</dependency>
首选方法是创建自己的远程存储库。
有关如何执行此操作的详细信息,请参阅此处。查看“上载到远程存储库”部分。
当然,您可以将jar添加到该文件夹中。但也许这并不是你想要实现的。。。
如果您需要这些jar进行编译,请检查这个相关问题:我可以在不安装jar的情况下将它们添加到maven 2构建类路径吗?
此外,在任何人提出建议之前,不要使用系统范围。
命令行:
mvn install:install-file -Dfile=c:\kaptcha-{version}.jar -DgroupId=com.google.code
-DartifactId=kaptcha -Dversion={version} -Dpackaging=jar
要安装第三方jar,请调用如下命令
mvn install:install-file -DgroupId= -DartifactId= -Dversion= -Dpackaging=jar -Dfile=path
推荐文章
- 在流中使用Java 8 foreach循环移动到下一项
- 访问限制:'Application'类型不是API(必需库rt.jar的限制)
- 用Java计算两个日期之间的天数
- 如何配置slf4j-simple
- 在Jar文件中运行类
- 带参数的可运行?
- 我如何得到一个字符串的前n个字符而不检查大小或出界?
- 我可以在Java中设置enum起始值吗?
- Java中的回调函数
- c#和Java中的泛型有什么不同?和模板在c++ ?
- 在Java中,流相对于循环的优势是什么?
- Jersey在未找到InjectionManagerFactory时停止工作
- 在Java流是peek真的只是调试?
- Recyclerview不调用onCreateViewHolder
- 将JSON字符串转换为HashMap