I have an external library that needs to be dynamically linked with a test in my java project. The project is setup using maven, and I need to add the following to my vm arguments in eclipse for the test to pass:
-Djava.library.path=${env_var:HOME}/.m2/repository/natives/dist/lib -ea
Unfortunately this means that running the test from maven using: mvn test will always fail.
One work around is to call mvn with a -DargLine argument like so:
mvn test -DargLine="-Djava.library.path=/Users/rob/.m2/repository/natives/dist/lib -ea"
However, clearly this has the problem of being specific to my machine, so I can’t put it directly in the pom file. I guess what I’m looking for is a way of modifying that string on a per machine basis kinda like the first line does for eclipse.
I’m also curious how I could put it into the POM file, I’ve tried placing it inside of <argLine> tags, but that doesn’t seems to work, is there something I’m missing:
<argLine>-Djava.library.path=/Users/rob/.m2/repository/natives/dist/lib -ea</argLine>
After some research I’ve discovered a decent solution to my problem.
In maven your
settings.xmlfile, you can define a location for thelocalRepositoryhere are the defaults if you set nothing:As you can see this matches at least the first part of the directory I was trying to set:
/Users/rob/.m2Since dynamic linking is OS specific, you may also want to setup a profile for alternate path suffixes. You can do this in a
.pomlike this:You can then use this property in the
.pomfor the project you wish to test. Under the plugins category you can add:Now maven can run those tests without users having to specify the location of the dynamically linked libraries. You can also handle users with different operating systems by just adding another profile.
Note: With regards to my problem with
<argLine>earlier. I think I was just using it in the wrong.pom