具有本机依赖项和复制文件的 Maven 项目
我有以下场景:
mylib 是一个库(我有其源代码,因此我想将它们放入 Maven 项目 mylib:mylib 中)。 这个库有一个 jar 依赖项,我只有 jar,并且在 Maven 存储库中找不到它(而且我也不想在那里安装它)。 为了使其编译,类似这样的事情可以工作:将jar文件添加到“lib”文件夹中的mylib项目,例如“lib/thirdpartylib.jar”,并在mylib的pom.xml中,添加具有自选组/的依赖项工件/版本和“
”条目。 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本思想如下:
因此,您必须执行以下步骤:
现在您应该能够再次使用 Maven 进行构建过程,并且通过使用诸如
maven-assemble-plugin
之类的其他插件,您可以将所有内容打包在一起。The base idea is the following:
So you have to do the following steps:
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.