我想在maven中构建一个带有依赖项的.jar文件。不幸的是,我必须在buildpath中包含一些外部.jars。当我现在尝试使用maven包构建此项目时,我将收到一个错误,即找不到那些外部.jars。
如何调整我的pom文件来添加这些罐子?当前:
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
您可以将构建路径中的外部jar包含为<scope>system</scope>
的依赖项。
检查这个link
您需要使用以下命令将外部jar添加到.m2文件夹中
mvn install:install-file -Dfile=[JAR] -DgroupId=[some.group] -DartifactId=[Some Id] -Dversion=1.0.0 -Dpackaging=jar
这会将给定的jar添加到.m2文件夹中。之后转到pom.xm并添加具有给定组ID,工件ID和版本的依赖项。
一个简单的解决方案是将其添加到本地maven存储库中
一种方法是通过上一篇文章中建议的mvn install命令。
另一个简单的方法是,1)在你的eclipse中右键单击项目选择Maven选项。 2)选择“安装或将工件部署到maven存储库”选项,然后单击“下一步”。 3)点击Artifact文件复选框旁边的浏览并选择你的jar文件4)输入GroupId和ArtifactId并确保版本确保生成pom和create校验和,并且打包是jar
点击完成,Wallah!您的工作已完成,jar已添加到您的本地存储库中,您可以在settings.xml或m2目录中定义该存储库
现在只需按照导入输入的GroupId,ArtifactId和jar版本添加简单的maven依赖项,即外部jar将由maven打包。