Search code examples
maven-2maven-pluginm2eclipsesurefire

Maven Eclipse unit test configuration


I use Eclipse and for some of my unit tests, I need to set some JVM args for the test to work, -Djava.library.path in particular. I set it in my POM file as follows:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-surefire-plugin</artifactId>
  <configuration>
    <argLine>-Djava.library.path=target/dll</argLine>
  </configuration>
</plugin>

and it works correctly when I build with Maven. However, when I run in Eclipse (even with the Maven plug-in installed - I have everything else in my Eclipse environment working properly with maven), this JVM argument is not applied. Does anyone know why this is or how to fix this?


Solution

  • Running the test in Eclipse with the JUnit test runner does not invoke maven , even if you are using m2eclipse.

    I suggest you either:

    • create a maven launch configuration for the test goal;
    • add -Djava.library.path=target/dll to your JVM arguments in the JUnit launch configuration.