具有本机依赖项和复制文件的 Maven 项目

发布于 2024-07-30 03:37:34 字数 1046 浏览 5 评论 0原文

我有以下场景:

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

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

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

使用 mylib 的任何其他项目(例如项目“X”)将需要

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

并且必须设置 java.library。目录的路径(例如“.”),以便执行 VM 找到第三方 jar 和 dll。

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

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

任何建议表示赞赏!

I have the following scenario:

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.

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:

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

- mylib.jar
- thirdpartylib.jar
- thirdpartylib.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.

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?

[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).

Any suggestions are appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伏妖词 2024-08-06 03:37:34

基本思想如下:

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

因此,您必须执行以下步骤:

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

现在您应该能够再次使用 Maven 进行构建过程,并且通过使用诸如 maven-assemble-plugin 之类的其他插件,您可以将所有内容打包在一起。

The base idea is the following:

  • Maven is good in handling with one result per Maven POM.
  • It is possible to have libraries and dependencies to these libraries in your local repositories only.

So you have to do the following steps:

  1. Define for the additional library a separate project (or a module in your project) and define the library as the result.
  2. Change your POM so that this POM has now a dependency to the new project.
  3. Do the same steps for your DLL (see the post Managing DLL dependencies with Maven) how to do that).
  4. Deploy your additional library and your DLL to your local repository.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文