是否有任何插件可以启用非 Maven 依赖项加载/使用?
我需要在我的项目中使用第三方JAR库(实际上它是 Dresden OCL for Eclipse),未作为 Maven 工件提供。相反,它只是一个可下载的 JAR 文件。我可以指示 Maven 使用此 JAR 文件,就像使用
一样吗?我想应该有一些插件用于此目的?
附注我只是不想将 35Mb 的第三方二进制文件添加到我的 SVN 存储库中。
以这种方式配置就好了:
<build>
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>non-maven-dependencies-injector</artifactId>
<configuration>
<libraries>
<library>http://www.example.com/something*.jar</library>
<library>http://www.example.com/something-else*.jar</library>
</libraries>
</configuration>
</plugin>
<plugins>
</build>
这个插件将 1) 下载这些 JAR 文件,2) 将它们作为依赖项添加到 pom.xml
中。也许这个插件可以将它们存储在 ~/.m2/temp/
中的某个位置...
I need to use a third-party JAR library in my project (actually it's Dresden OCL for Eclipse) that is not provided as a Maven artifact. Instead, it's just a downloadable JAR file. Can I instruct Maven to use this JAR file the same way I'm using <dependencies>
? I suppose that there should be some plugin for this purpose?
ps. I just don't want to add 35Mb of third-party binaries into my SVN repository.
Would be nice to have it configured this way:
<build>
<plugins>
<plugin>
<groupId>com.example</groupId>
<artifactId>non-maven-dependencies-injector</artifactId>
<configuration>
<libraries>
<library>http://www.example.com/something*.jar</library>
<library>http://www.example.com/something-else*.jar</library>
</libraries>
</configuration>
</plugin>
<plugins>
</build>
And this plugin would 1) download these JAR files, and 2) add them as dependencies into pom.xml
. Maybe this plugin could store them somewhere in ~/.m2/temp/
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
您可以将其安装在本地或将其部署到站点本地(例如公司范围)存储库。
如果您使用的依赖项 maven 在配置的存储库中找不到,它甚至会为您提供所需的命令:
请注意:这样您只能将 .jar 添加到您的存储库中,将不会有 pom 一起指定临时依赖项。因此,如果您的第三方库有自己的依赖项,您必须将它们手动添加到您的 pom.xml 中,因为不会自动解析。
You can install it local or deploy it to your site-local (e.g. company-wide) repository.
If you use a dependency maven cannot find in the configured repositories, it even gives you the required commands:
Please note: This way you only add the .jar to your repository, there will be no pom along with it to specify transient dependencies. So if your third-party library has dependencies of it's own you'll have to add them manually to your pom.xml as there will be no automatic resolution.
这里提到的“mvn install:install-file”将帮助您将 jar 安装到本地存储库中。但是,如果您想让这些 jar 文件随后自动可供项目的开发人员使用,请将相关部分复制到项目中每个人都可以使用的存储库,并使用标记使该存储库可用,例如通过将所有文件签入SVN。请参阅 http://code.google.com/p/codebistro/wiki/BuildNumber#例如,Maven_Plugin_Example 指的是 SVN 托管的存储库。
PS 祝 SV 旅途平安!
"mvn install:install-file" mentioned here will help you to install the jars into your local repository. However, if you want to make these jars subsequently available to the developers on the project automaticall, copy the relevant pieces to a repository available to everybody on the project and make this repository available using the tag, for example by checking all the files into the SVN. See http://code.google.com/p/codebistro/wiki/BuildNumber#Maven_Plugin_Example which refers to a SVN-hosted repository for example.
P.S. Have a safe trip to the SV!
这里有一种不同的方法,可以在项目目录中添加 Maven 存储库,将其用作
pom.xml
中的存储库,并在 SVN 上与签出该项目的任何人共享该存储库。 从这里交叉发布。在您的项目目录中,创建一个名为
repo 的文件夹
,我们将使用它作为基于文件夹的 Maven 存储库。将以下文件存储库添加到您的项目
pom.xml
:使用以下命令将外部 jar 部署到文件存储库:
接下来,您可以在项目中添加对 jar 的正常依赖项
pom.xml
,使用上面传递的 groupId、artifactId 和版本的值。然后,您可以将存储库文件夹添加到 SVN,并将更改提交到您的pom.xml
。现在,任何检查您的项目的开发人员都可以毫不费力地使用相同的依赖项。Here's a different approach that'll let add a Maven repository inside the project directory, use that as a repository in you
pom.xml
, and share the repository on SVN with anyone checking out the project. Crosspost from here.In your project directory, create a folder called
repo
, which we'll use as a folder based Maven repository.Add the following file repository to your project
pom.xml
:Deploy the external jar(s) to the file repository with the following command:
Following this you can just add a normal dependency on the jar in your project
pom.xml
, using the values for groupId, artifactId and version you passed above. You can then add the repo folder to SVN, and commit the changes to yourpom.xml
. Any developer checking out your project will now be able to use the same dependency without any effort.是的,您可以使用 maven-install 插件将其安装到本地存储库中。
如果您希望其他团队成员能够下载此依赖项,而无需自己安装,则需要设置自己的工件存储库,并在那里部署工件使用 maven-deploy-plugin 的方式与在本地安装它的方式相同。
yes you can install it into your local repository with maven-install plugin
If you want your other team members to be able to download this dependency without having to install it them thelves, you need to setup your own artifact repo, and deploy the artifact there with maven-deploy-plugin in same way as you installed it localy.
是的。 maven-external-dependency- 支持此功能(使用非 Mavenized 依赖项)插件。
示例:
它还可以从 zip 文件中提取工件:
Yes. This (using non-Mavenized dependencies) is supported by the maven-external-dependency-plugin.
Example:
It can also extract artifacts from zip files:
您可以在 pom.xml 中使用“system”范围来获取本地库依赖项:
AFAIK,您几乎可以使用您想要的 groupId、artifactId 和 version。请参阅 Maven 系统依赖 和 这个问题。
You can use "system"-scope in your pom.xml for local library dependencies:
AFAIK, you can use pretty much what you want for groupId, artifactId and version. See Maven System Depencies and this question.
以您的示例 Dresden OCL 有超过 20 个 JAR 文件,并且您需要将其分发给许多开发人员,最好的解决方案是在某处安装存储库管理器(例如 nexus 或 artifactory),花点时间将这 20 个 jar 上传到该管理器存储库,并使用它们。最好的办法是将它们放入私有 groupId 中,因此,如果它们有时会发布到 m2 存储库,则不会出现名称冲突。
另一点是询问 Dresden OCL 维护者,他们是否可以提供 m2 存储库。现在 m2eclipse 是一个 eclipse 孵化器项目,这可能会让更多人感兴趣。
Taking that your example Dresden OCL has over 20 JAR files, and you need to distribute it to many developers, the best solution would be to install a repository manager somewhere (like nexus or artifactory), take your time to upload these 20 jars to that repository, and use them. Best bet would be to put them in a private groupId, so if they'll get published to a m2 repo sometime, you won't end up with name conflicts.
Another point, would be to ask the Dresden OCL Maintainers, if they can offer a m2 repository. Now that m2eclipse is an eclipse incubator project, this might interest more people.