Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set vm default arguments via maven for eclipse

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 which doesnt seem very good.

Has anybody got any ideas as to how to solve this.

cheers,

David.

like image 590
David Turner Avatar asked Dec 16 '10 10:12

David Turner


2 Answers

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.

like image 69
James Camfield Avatar answered Oct 13 '22 07:10

James Camfield


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:

  1. The solution is not system independent since you specify the suffix of the file in the parameter to getResource()
  2. 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.
like image 43
Eduard Wirch Avatar answered Oct 13 '22 07:10

Eduard Wirch