Is it possible to pass -Djava.library.path sequentially to the maven test from within the POM file?

I have an external library that should be dynamically linked to a test in my java project. The project is being configured using maven, and I need to add the following vm arguments to eclipse to pass the test:

-Djava.library.path=${env_var:HOME}/.m2/repository/natives/dist/lib -ea

Unfortunately, this means running the test from maven with: mvn testwill always fail.

One job is to call mvnwith an argument -DargLineas follows:

mvn test -DargLine="-Djava.library.path=/Users/rob/.m2/repository/natives/dist/lib -ea"

However, it is obvious that the problem is with my machine, so I cannot install it directly in the pom file. I assume that what I am looking for is a way to change this line on every machine basis, like the first line for eclipse.

I am also curious how I can put it in a POM file, I tried to put it inside the tags <argLine>, but this does not seem to work, there is something that I am missing:

<argLine>-Djava.library.path=/Users/rob/.m2/repository/natives/dist/lib -ea</argLine>

+5
source share
1 answer

After some research, I found a decent solution to my problem.

In maven your file, settings.xmlyou can determine the location for localRepository, if this default value is set, if you did not install anything:

  • Unix / Mac OS X - ~ / .m2
  • Windows - C: \ Documents and Settings \ username .m2

As you can see, this matches at least the first part of the directory I tried to install: /Users/rob/.m2

, . .pom :

<profile>
    <id>OSX</id>
        <activation>
            <os>
                <family>mac</family>
            </os>
        </activation>
    <properties>
        <dynamic.libLoc>${settings.localRepository}/natives/dist/lib</dynamic.libLoc>
    </properties>
</profile>

.pom , . :

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <configuration>
      <argLine>-Djava.library.path=${dynamic.libLoc}</argLine>
    </configuration>
</plugin>

maven . , .

. <argLine> . , .pom

+3

All Articles