在Maven中本地引用依赖jar [英] Referring dependency jar locally in Maven
问题描述
在我的项目中,我使用的是公司的Maven存储库中不存在的外部jar。所以我收到以下错误
In my project, I am using an external jar which is not present in company's Maven repository. So I am getting the following error
Could not resolve dependencies for project.Could not find artifact in http://company-name/maven2
是否有任何方法可以在本地引用此jar作为解决方法,直到公司添加该jar在其存储库中。就像我创建lib文件夹并将jar放在该文件夹中一样。我可以让Maven从lib文件夹中取出jar而不是从maven存储库下载吗?
Is there any way in which this jar can be referenced locally as workaround till company add that jar in its repository. Like if I create lib folder and put jar in that folder. Can I ask Maven to take jar from that lib folder instead of downloading from maven repository?
推荐答案
最好的方法是重复使用该工具 AddJars Maven插件,可在Google Code上找到。从此以后,包含jar的最简单方法是将它存储在Maven项目内的子文件夹中,比如 lib
。
The best way is to recur to the utility AddJars Maven Plugin, available on Google Code. Henceforth, the simplest way to include a jar is to store it in a subfolder, say lib
, located inside of your Maven project.
然后在你的pom.xml中添加:
Then in your pom.xml simply add:
<plugin>
<groupId>com.googlecode.addjars-maven-plugin</groupId>
<artifactId>addjars-maven-plugin</artifactId>
<version>1.0.5</version>
<executions>
<execution>
<goals>
<goal>add-jars</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/lib</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
有关插件配置的更多信息这里。特别是在NetBeans下需要一些额外的步骤来启用自动完成。
There is more about plugin configuration here. In particular some additional steps are required under NetBeans to enable autocompletion.
不幸的是,需要Maven 3.0.3或更高版本。
这篇关于在Maven中本地引用依赖jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!