本文介绍了如何从POM设置eclipse使用的java.library.path?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用maven定义我的项目.我的依赖项之一在运行时需要本机DLL,因此在测试和调试中都需要它.本地DLL在已知位置可用.我想要一个可以一次性签入的解决方案,并且无需所有开发人员手动设置即可适用于所有开发人员.

I'm using maven to define my projects. One of my dependencies requires a native DLL at runtime, and consequently it's needed in tests and for debugging. The native DLL is available at a known location. I want a solution that I can check in once and will work for all developers without manual setup by each dev.

我知道我可以在运行配置"中手动设置java.libary.path,这将允许它查找本机DLL,但这需要为每个开发人员进行手动设置.

I know I can set the java.libary.path manually in "run configurations", which will allow it to find the native DLL, but this requires manual setup for each developer.

我知道我也可以为给定的项目依赖项设置java.library.path,但这再次对于特定的开发人员而言是本地的.

I know I can also set the java.library.path for a given project dependency, but again this is local to a particular developer.

最后,我知道我可以设置surefire插件来指定java.library.path,但这仅对通过maven触发的测试有用-因此对我们的构建服务器非常有用,但对使用JUnit运行器的开发人员无济于事eclipse中,或者想直接从eclipse中调试或运行代码.

Finally I know I can set the surefire plugin to specify the java.library.path, but this is only useful for tests triggered via maven - so it's great for our build server, but doesn't help devs using the JUnit runner in eclipse, or wanting to debug or run code directly from eclipse.

有没有出路?

推荐答案

我发现 maven-nativedependencies-plugin 似乎可以解决此问题.

I've found that the eclipse m2e connector that goes with the maven-nativedependencies-plugin seems to fix this.

根据专家文档:

此Eclipse插件是m2eclipse的扩展,它可以检测您是否 配置了maven插件,如果执行了该插件,则执行 解压缩本机,并配置本机库位置.

This Eclipse plugin is an extension to m2eclipse, it detects if you have the maven plugin configured, and if you do it executes the unpacking of natives, and configures the Native Library Location.

如果导入具有Mavennatives插件的Maven项目 配置,并且在导入时具有m2eclipse集成插件 在执行清理操作时,也会提取本地人 蚀将提取本地人.

If you import a maven project that has the mavennatives plugin configured, and you have the m2eclipse integration plugin, on import the natives will be extracted, also when performing a clean from eclipse the natives will be extracted.

因此,如果您同时使用这两种工具,则使用本机依赖项不需要 手动配置,而不是pom中的内容,只需运行您的应用 而且有效.

So, if you use both these tools, using native dependencies requires no manual configuration, other than whats in the pom, just run your app and it works.

如果我安装了连接器,并向我的POM中添加了navennatives,然后重新加载pom(在程序包浏览器中的项目上单击鼠标右键> maven>更新项目),则该项目的本地库位置"会自动填充(要查看此内容,请右键单击项目>属性> Java构建路径>库>本机库位置)

If I have the connector installed, and add mavennatives to my POM, then reload the pom (right-click on project in package explorer > maven > update project), the "Native library location" of the project is populated automatically (to see this, right click on project > properties > java build path > libraries > native library location)

这似乎可以用于调试,JUnit运行程序等.

This seems to work for debugging, JUnit runner, etc.

它确实要求每个开发人员都安装该插件,该插件是手动的(与安装eclipse一样手册);但是,至少一旦安装一次,它就可以通过POM为配置为维护性的任何/所有本机依赖关系工作.

It does require that every developer install the plugin, which is manual (as manual as installing eclipse); however, at least once installed once it will work for any/all native depdendencies configured for mavennatives via a POM.

这篇关于如何从POM设置eclipse使用的java.library.path?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 00:33