简体   繁体   English

链接maven依赖于非maven项目

[英]Link maven dependencies on non maven project

I have two projects in Eclipse, the first project depends on maven, the second project which dependent on the first one does NOT depend on maven. 我在Eclipse中有两个项目,第一个项目依赖于maven,第二个项目依赖于第一个项目不依赖于maven。

The first project downloads external libraries like jar files and natives to the .m2 maven folder. 第一个项目将外部库(如jar文件和本机)下载到.m2 maven文件夹中。 However the second project gives a ClassNotFoundException since it cant find the jar files and the native files from the first project. 但是第二个项目提供了ClassNotFoundException,因为它无法从第一个项目中找到jar文件和本机文件。

Is it possible to link these downloaded jars+dlls with the second project without having to reference in the build path->libraries in the second project properties ? 是否可以将这些下载的jar + dll链接到第二个项目,而无需在第二个项目属性中的构建路径 - >库中引用?

I would appreciate any help. 我将不胜感激任何帮助。

In your Maven project, use Assembly plugin to create an Uber-jar that contains the project build artifact and all its dependencies ( mvn assembly:assembly -DdescriptorId=jar-with-dependencies ). 在Maven项目中,使用Assembly插件创建一个Uber-jar,其中包含项目构建工件及其所有依赖项( mvn assembly:assembly -DdescriptorId=jar-with-dependencies )。 Then, reference that from project #2, either with a relative path or by using an ant build task to copy it into your other project's lib directory (assuming you have such a directory). 然后,从项目#2引用它,或者使用相对路径,或者使用ant构建任务将其复制到另一个项目的lib目录中(假设您有这样的目录)。 Also, although it's frowned upon, you could configure the assembly plugin so that your Uber jar artifact always has the same finalName . 此外,虽然它不受欢迎,但您可以配置程序集插件,以便您的Uber jar工件始终具有相同的finalName

Is it possible to link these downloaded jars+dlls with the second project without having to reference in the build path->libraries in the second project properties? 是否可以将这些下载的jar + dll链接到第二个项目,而无需在第二个项目属性中的构建路径 - >库中引用?

I don't think so. 我不这么认为。

But maybe you could create a 3rd project (which is a Maven project) that depends on the first one, and on the JAR (or whatever) file created by the 2nd one as a non-repository dependency. 但也许您可以创建第3个项目(这是一个Maven项目),它依赖于第一个项目,以及第二个项目创建的JAR(或其他)文件作为非存储库依赖项。

Having said that, anything you do is going to be a bit of a hack. 话虽如此,你所做的任何事情都会变得有点黑客。 You'd be better of either turning the 2nd project into a proper Maven project, or creating a custom build script that manually pulls the 2nd project's dependencies from somewhere. 您最好将第二个项目转换为适当的Maven项目,或者创建一个自定义构建脚本,从某个地方手动提取第二个项目的依赖项。 (I think that Ivy could help you with that ... assuming you use Ant in the 2nd project.) (我认为Ivy可以帮助你...假设你在第二个项目中使用Ant。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM