从现有jar创建maven工件的最佳方法 [英] Best way to create a maven artifact from existing jar

查看:144
本文介绍了从现有jar创建maven工件的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm mavenizing some projects.

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

These projects all depend on a number of libraries, most of them are available in the maven repo. For the other libraries, I'd like to create a maven artifact, so I can use it as an dependency. The problem is, I only have jar files of these libraries.

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

What is the best way to create artifacts from existing jar files?

推荐答案

如果您没有使用远程存储库(这是个人开发的常见情况),只需 <$ c使用本地存储库中安装 这些工件-plugin / install-file-mojo.htmlrel =noreferrer> install:install-file mojo:

If you're not using a remote repository (which is a common situation for personal development), simply install these artifacts in your local repository using the install:install-file mojo:

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

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

But obviously, this will make your build non portable (this might not be an issue though). To not sacrifice the portability, you'll have to make the artifacts available in a remote repository. In a corporate context, the common way to deal with that is to install an enterprise repository (and in that case, to deploy the artifacts indeed).

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

Update: Once your artifact is installed in your local repository, simply declare a <dependency> element in your pom like for any other dependency, e.g.:

<dependency>
  <groupId>aGroupId</groupId>
  <artifactId>aArtifactId</artifactId>
  <version>1.0.12a</version>
  <packaging>jar</packaging>
</dependency>

这篇关于从现有jar创建maven工件的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆