Skip to main content

Maven: Using JUnit with DLLs

Posted by kschaefe on August 14, 2009 at 5:54 AM PDT

Since I was unable to quickly google the solution for my Maven DLL problem, I thought I'd post a quick blog about it. Here's the situation, I have tests that rely on artifacts that are DLLs (in my case these were the Java3D DLLs). So, I needed to be able to have the DLLs in a known location so that the tests could run, but did not want to check those items into the SCM repository, nor install them locally on the Hudson server. I made two changes to the POM file.

First I used the dependency plugin to find and output all the DLLs.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.1</version>
    <executions>
        <execution>
            <id>copy-dlls</id>
            <phase>process-test-resources</phase>
            <goals>
                <goal>copy-dependencies</goal>
            </goals>
            <configuration>
                <includeTypes>dll</includeTypes>
                <excludeTypes>*</excludeTypes>
                <stripVersion>true</stripVersion>
                <silent>true</silent>
                <outputDirectory>${project.build.directory}/dll</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
            </configuration>
        </execution>
    </executions>
</plugin>

 

Then, I modified the surefire plugin to use the output directory as part of the java.library.path.

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

 

Hopefully, this will make it easier for the next guy trying to solve the same problem. If anyone has a better way of doing it, please let me know.

Related Topics >>

Comments

I've never been able to get the systemProperties line to work for DLLs. Ever. The property is updated (if you dump it you can see that) but the libraries won't load. I think it's an ordering dependency with the JVM....or I'm just doing something wrong.

Tiny suggestion: you can use the systemProperties element instead of argLine.