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

查看:101
本文介绍了具有本机依赖性和复制文件的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</systemPath>"条目的依赖项. 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?

[我目前的黑客解决方案是,我在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部署到本地存储库中.
  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.

现在,您应该可以再次使用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天全站免登陆