在构建之前将jar添加到Maven本地存储库 [英] add jar to the maven local repository before build
问题描述
我有第三方jar文件,该文件不在项目目录中,该文件不存在,我想在执行mvn install时将其添加到本地存储库中,这是我目前的代码
i have third part jar file which doesn't exist remotely the file located inside the project directory , i want to add this jar into the local repository when i execute mvn install, my current code for doing that
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>install-file</goal>
</goals>
<configuration>
<groupId>myJar1.0</groupId>
<artifactId>myJar1.0</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>myJar1.0.jar</file>
</configuration>
</execution>
</executions>
</plugin>
推荐答案
使用存储库管理器是最佳解决方案.但是,以下解决方案可以完全通过pom.xml
配置进行设置(无需开发人员干预):
Using a repository manager is the best solution. However, here's a solution that can be setup entirely through pom.xml
configuration (without developer interventions):
<repositories>
<repository>
<id>project-local-repo</id>
<url>file://${project.basedir}/src/lib/</url>
</repository>
</repositories>
将库移动/重命名为$ {project.basedir}/src/lib/some-group-name/myJar-1.0.jar
Move/rename your library to ${project.basedir}/src/lib/some-group-name/myJar-1.0.jar
<dependency>
<groupId>some-group-name</groupId>
<artifactId>myJar</artifactId>
<version>1.0</version>
</dependency>
将在每次构建时获取依赖项. 我在这里写了一个类似的答案:为REST运行Spring Boot
The dependency will be picked up at every build. I wrote a similar answer here: running Spring Boot for REST
这篇关于在构建之前将jar添加到Maven本地存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!