I want to specify vm args of -Djava.library.path=./src/main/resources so that a dll is picked up automatically, and I want to specify this in maven, so other developers don't have to manually configure eclipse.
I was thinking perhaps the the maven eclipse plugin might help, so I could do something like
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.7</version>
<configuration>
DO MAGIC HERE ???? <<-----
</configuration>
</plugin>
But I can't see a way to add VM args from within the plugin.
I have fixed this for running my tests via maven at the command line by
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4.3</version>
<configuration>
<argLine>-Xmx768m -Xms128m -Djava.library.path=${basedir}/src/main/resources/</argLine>
</configuration>
</plugin>
My current solution, is that I will have to tell the developers to add this manually to eclipse whic开发者_C百科h doesnt seem very good.
Has anybody got any ideas as to how to solve this.
cheers,
David.
Maybe this should be a more general question:
Is there any way of adding a DLL to the VM without having to specify it through the library path?
I've read somewhere that putting the dll in the application root and specifying the DLL in the MANIFEST.MF with its hashcode triggers the VM to automatically pick it up. That could be completely wrong though.
My interpretation of your problem is that your application is loading a DLL and this DLL is located in your project in the resources folder. Correct?
You can get the full path of the DLL if the DLL is inside a folder in the class path and load it using:
// assuming dll is located in the default package
URI dllUri = this.getClass().getResource("/mydll.dll").toURI();
File dllFile = new File(dllUri);
System.load(dllFile.getCanonicalPath());
This is independent of maven. There are only two problems:
- The solution is not system independent since you specify the suffix of the file in the parameter to getResource()
- This won't work if the DLL is inside a JAR. For this case we build a JAR extractor which will extract the DLL to a temp folder and call System.load() with the file in the temp folder.
精彩评论