我正在做一些项目。
这些项目都依赖于许多库,其中大部分都可以在 maven repo 中找到。 对于其他库,我想创建一个 Maven 工件,所以我可以将它用作依赖项。问题是,我只有这些库的 jar 文件。
从现有 jar 文件创建工件的最佳方法是什么?
最佳答案
如果您不使用 remote 存储库(这是个人开发的常见情况),只需 install
这些工件在您的本地 存储库中使用 install:install-file
魔力:
mvn install:install-file
-Dfile=<path-to-file>
-DgroupId=<group-id>
-DartifactId=<artifact-id>
-Dversion=<version>
-Dpackaging=<packaging>
-DgeneratePom=true
Where: <path-to-file> the path to the file to load
<group-id> the group that the file should be registered under
<artifact-id> the artifact name for the file
<version> the version of the file
<packaging> the packaging of the file e.g. jar
但显然,这会使您的构建不可移植(尽管这可能不是问题)。为了不牺牲可移植性,您必须使工件在远程存储库中可用。在企业环境中,处理该问题的常用方法是安装企业存储库(在这种情况下,安装到 deploy
确实是工件)。
更新:在本地存储库中安装工件后,只需声明 <dependency>
你的 pom 中的元素就像任何其他依赖项一样,例如:
<dependency>
<groupId>aGroupId</groupId>
<artifactId>aArtifactId</artifactId>
<version>1.0.12a</version>
<packaging>jar</packaging>
</dependency>
关于java - 从现有 jar 创建 maven 工件的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2177069/