具有本机依赖和复制文件的 Maven 项目 [英] Maven project with native dependency and copying files

查看:23
本文介绍了具有本机依赖和复制文件的 Maven 项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下场景:

mylib 是一个库(我有它的源代码,所以我想将它们放入一个 Maven 项目 mylib:mylib 中).这个库有一个 jar 依赖项,我只有 jar,并且在 Maven 存储库中找不到它(我也不想在那里安装它).为了使它编译,这样的事情会起作用:将jar文件添加到lib"文件夹中的mylib项目中,例如lib/thirdpartylib.jar"并在 mylib 的 pom.xml 中添加一个具有自选组/工件/版本和<scope>system</scope><systemPath>${project.basedir"的依赖项}/lib/thirdpartylib.jar"条目.mylib 项目可以正常编译.

mylib is a library (for which I have the sources, so I'd like to put them into a Maven project mylib:mylib for example). This library has a jar dependency for which I only have the jar, and it is not to be found in the Maven repository (and I do NOT want to install it there either). To make it compile, something like this would work: add the jar file to the mylib project in a "lib" folder, e.g. "lib/thirdpartylib.jar" and in mylib's pom.xml, add a dependency with self-chosen group/artifact/version and a "<scope>system</scope><systemPath>${project.basedir}/lib/thirdpartylib.jar</systemPath>" entry. The mylib project will compile fine.

请注意,mylib 还具有对 dll 文件的运行时依赖项,例如thirdparty.dll.但是对于编译来说,这并不重要.

Note that mylib also has a runtime dependency to a dll file, say thirdparty.dll. But for compilation this is not important.

但是,现在我想知道如何实现以下目标:

However, now what I am wondering how to achieve the following:

任何其他项目,例如使用 mylib的项目X"将需要

Any other projects, e.g. project "X", that uses mylib, will need the

- mylib.jar
- thirdpartylib.jar
- thirdpartylib.dll

,

它必须将 java.library.path 设置为目录(例如."),以便执行 VM 找到第三方 jar 和 dll.

and it'll have to set the java.library.path to the directory (e.g. ".") such that the thirdparty jar and dll are found by the executing VM.

我担心的是:我希望第三方 jar/dll 的东西由 mylib 项目负责.IE.我想定义知识,您需要将第三方 jar 和 dll 复制到目标文件夹并且 java.library.path 引用它们,成为 mylib 项目的一部分(mylib pom 知道事情是怎样的用于其他项目).然而,我希望将这些知识(即复制指令,无论它们在 Maven 中如何准确完成)传递给使用 mylib 的任何其他项目,例如 X.这有可能吗?

My concern is this: I would like the thirdparty jar/dll things to be the responsibility of the mylib project. I.e. I want to define the knowledge, that you need to copy the thirdparty jar and dll to the target folder and that java.library.path refers to them, to be part of the mylib project (the mylib pom knows how the thing is to be used in other projects). Yet, I want this knowledge (i.e. copy instructions, regardless how they are exactly done in Maven) to be transitively handed over to any other project using mylib, like X for example. Is that somehow possible?

[我现在的 hack 解决方案是我在 X 中有第三方东西的副本,但即便如此我也不知道如何复制/处理 dll 文件,所以我必须写一个自述文件说dll 文件必须复制到正在执行的 VM 的 bin 文件夹中).

[My hack solution for now would be that I have a copy of the thirdparty things in X, but even then I dunno how to copy/deal with the dll file, so I'd have to write a readme saying that the dll file has to be copied to the bin folder of the executing VM).

欢迎提出任何建议!

推荐答案

基本思路如下:

  • Maven 擅长处理每个 Maven POM 一个结果.
  • 只能在本地存储库中拥有这些库的库和依赖项.

所以你必须执行以下步骤:

So you have to do the following steps:

  1. 为附加库定义一个单独的项目(或项目中的一个模块)并将库定义为结果.
  2. 更改您的 POM,以便此 POM 现在对新项目具有依赖关系.
  3. 对您的 DLL 执行相同的步骤(请参阅帖子使用 Maven 管理 DLL 依赖项) 怎么做).
  4. 将您的附加库和 DLL 部署到本地存储库.

现在您应该可以再次使用 Maven 进行构建过程了,并且通过使用诸如 maven-assembly-plugin 之类的附加插件,您可以将所有内容打包在一起.

Now you should be able to use Maven for the build process again, and by using additional plugins like the maven-assembly-plugin, you are able to pack all together.

这篇关于具有本机依赖和复制文件的 Maven 项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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