这是我学习 Maven 的头几天,但我仍在努力学习基础知识。我有一个需要在我的项目中引用的外部 .jar 文件(在公共(public)存储库中不可用),我试图找出我的最佳选择是什么。
这是一个小型项目,没有库的中央存储库,因此它必须是本地存储库(以某种方式添加到源代码控制,不知道它是否应该这样工作?)或 .jar 需要存储在任何正式存储库之外的磁盘上。
1) 考虑到我希望项目和库都在源代码管理中,使用 maven 将 .jar 文件添加到我的项目引用中的最佳选择是什么?
2) 我似乎仍然无法让 Eclipse 看到依赖关系。我手动将它添加到 pom 的部分,它在 m2eclipse 的 Dependencies 列表中显示得很好。 mvn compile 和 mvn package 都成功了,但是运行程序会导致:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
LibraryStuff cannot be resolved to a type
这是在将 POM 编辑为:
<dependency>
<groupId>stuff</groupId>
<artifactId>library</artifactId>
<version>1.0</version>
<systemPath>${lib.location}/MyLibrary.jar</systemPath>
<scope>system</scope>
</dependency>
我是否应该执行 mvn install:install-file 即使我已经像上面那样编辑了 pom.xml?
谢谢!
最佳答案
您可以创建一个 In Project Repository,这样您就不必每次在新计算机上工作时都运行 mvn install:install-file
<repository>
<id>in-project</id>
<name>In Project Repo</name>
<url>file://${project.basedir}/libs</url>
</repository>
<dependency>
<groupId>dropbox</groupId>
<artifactId>dropbox-sdk</artifactId>
<version>1.3.1</version>
</dependency>
/groupId/artifactId/version/artifactId-verion.jar
详细阅读这篇博文
https://web.archive.org/web/20121026021311/charlie.cu.cc/2012/06/how-add-external-libraries-maven
关于java - Maven:将自定义外部 JAR 链接到我的项目的最佳方式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5692256/