How to set java.library.path used by eclipse from POM?

I use maven to define my projects. One of my dependencies requires a built-in DLL at runtime, and therefore it is needed in tests and for debugging. A custom DLL is available in a known location. I want a solution that I can test once, and will work for all developers without manual configuration by each developer.

I know that I can install java.libary.path manually in "run configurations", which allows it to find the native DLL, but this requires manual configuration for each developer.

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

Finally, I know that I can install the surefire plugin to specify java.library.path, but this is only useful for tests run through maven, so this works great for our build server, but doesn't help developers using the JUnit runner in eclipse or want to debug or run code directly from eclipse.

Is there a way out?

+6
source share
2 answers

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

According to mavennatives docs:

Starting with version 0.0.7 of the maven-nativedependencies plugin, if you have m2eclipse, and the nativedependencies plugin configured to unpack the natives will run automatically, you will not need the eclipse plugin to unpack them. However, to configure the java.library.path environment variable in eclipse, you will need to do this either manually or automatically using the eclipse plugin.

This Eclipse plugin is an extension for m2eclipse, it detects if you configure the maven plugin, and if you do, unpack the natives and configure the location of the Native Library.

If you import the maven project with the mavennatives plugin configured, and you have the m2eclipse integration plugin, the natives will be extracted when importing, and if you perform a clean eclipse, the natives will be extracted.

So, if you use both of these tools, using your own dependencies does not require manual configuration, except that in the pump, just run the application and it works.

If I have a connector installed and mavennatives are added to my POM, reload pom (right-click the project in the explorer> maven> update project), the "Location of the source library" is populated automatically (to see this, right-click on the project> propertiesa> Java build path> libraries> local library location)

enter image description here

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

This requires that each developer install a plugin that is manual (as an Eclipse installation guide); however, at least once installed after it will work for any / all source parameters configured for mavennatives via POM.

+5
source

Properties Maven Plugin can help you pass system properties using the properties: set-system-properties to set system properties.

An example should look like this: -

<properties> <java.library.path>some/path</java.library.path> </properties> 

Hope this helps.

+2
source

All Articles