从现有jar创建maven工件的最佳方法

3wh*_*3wh 31 java maven-2 jar

我正在对一些项目进行整理.

这些项目都依赖于许多库,其中大多数都在maven仓库中提供.对于其他库,我想创建一个maven工件,所以我可以将它用作依赖项.问题是,我只有这些库的jar文件.

从现有jar文件创建工件的最佳方法是什么?

Pas*_*ent 29

如果您没有使用远程存储库(这是个人开发的常见情况),只需使用mojo 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
Run Code Online (Sandbox Code Playgroud)

但显然,这将使您的构建不可移植(虽然这可能不是问题).为了不牺牲可移植性,您必须在远程存储库中提供工件.在公司环境中,处理这种情况的常用方法是安装企业存储库(在这种情况下,deploy确实安装到工件).

更新:一旦您的工件安装在本地存储库中,只需<dependency>在您的pom中声明一个元素,就像任何其他依赖项一样,例如:

<dependency>
  <groupId>aGroupId</groupId>
  <artifactId>aArtifactId</artifactId>
  <version>1.0.12a</version>
  <packaging>jar</packaging>
</dependency>
Run Code Online (Sandbox Code Playgroud)


dan*_*ben 2

您可以使用Maven 部署插件将 JAR 文件(以及可选的 POM 文件,尽管默认情况下会为您创建一个)上传到您的 Maven 存储库。