Pick up native JNI files in Maven test (lwjgl)

后端 未结 3 1399
时光说笑
时光说笑 2021-01-01 02:08

I\'m creating a program with LWJGL and Maven, and I\'m writing unit tests for the graphical code. My problem is getting Maven to put the native binaries on the classpath so

相关标签:
3条回答
  • 2021-01-01 02:38

    According to http://maven.40175.n5.nabble.com/Trouble-with-Java-Native-Libraries-td114063.html,

    the surefire plugin starts the VM and then modifies the system properties before passing control to the junit test classes. This is too late for the VM, which needs to have the java.library.path set up at the time the VM is initialized.

    So we need to give the path to Surefire at startup. The following worked:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <forkMode>once</forkMode>
                    <argLine>-Djava.library.path=${project.build.directory}/libs/natives/win32:${project.build.directory}/libs/natives/linux:${project.build.directory}/libs/natives/macosx:${project.build.directory}/libs/natives/solaris</argLine>
                </configuration>
            </plugin>
    
    0 讨论(0)
  • 2021-01-01 02:47
    ...
    <project ...>
        ...
        <properties>
            ...
            <natives.version>0.0.6</natives.version>
        <properties>
        ...
        <build>
            ...
            <plugins>
                ...
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-surefire-plugin</artifactId>
                    <configuration>
                        <forkMode>once</forkMode>
                        <argLine>-Djava.library.path=target/natives</argLine>
                    </configuration>
                </plugin>
                <plugin>
                    <groupId>com.googlecode.mavennatives</groupId>
                    <artifactId>maven-nativedependencies-plugin</artifactId>
                    <version>${natives.version}</version>
                    <executions>
                        <execution>
                            <id>unpacknatives</id>
                            <phase>generate-resources</phase>
                            <goals>
                                <!--suppress MavenModelInspection (this line is for IDEA)-->
                                <goal>copy</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
            ...
        </build>
        ...
    </project>
    
    0 讨论(0)
  • 2021-01-01 02:49

    Does surefire configuration include setting java library path

    For example:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-surefire-plugin</artifactId>
        <configuration>
          <systemProperties>
            <property>
              <name>java.library.path</name>
              <value>target/lib/natives/</value>
            </property>
          </systemProperties>
        </configuration>
      </plugin>
    
    0 讨论(0)
提交回复
热议问题