我正在尝试在 headless 构建服务器上构建和测试 JavaFX 应用程序。我在本地使用 TestFX 和 Monocle https://github.com/TestFX/Monocle并且它工作正常。但是,我必须按照以下问题手动将 Monocle 安装到 java Extensions 文件夹中:JavaFX + maven + TestFX + monocle don't work together
现在我需要使用 headless 构建服务器来自动化我们的部署。我无法弄清楚如何使用 Maven 正确安装此 Java 扩展,而无需手动执行。这似乎是正确的功能:https://maven.apache.org/pom.html#Extensions ,
<extensions>
<extension>
<groupId>org.testfx</groupId>
<artifactId>openjfx-monocle</artifactId>
<version>8u76-b04</version>
</extension>
</extensions>
但是测试因 NoClassDefFoundException 失败(如果我手动将 jar 构建到扩展中,则不会发生这种情况)。我不知道如何调试这个,或者我是否使用了正确的功能。有什么建议么?
最佳答案
前段时间我也有过类似的头痛。我通过复制 openjfx-monocle
和 /target
下文件夹中扩展文件夹中的所有扩展来解决这个问题,然后将扩展系统属性设置为该路径。这样我就可以避免 NoClassDefFoundException 并在 Jenkins 上成功运行所有测试。这是个人资料部分:
<!--
This profile is used to make headless tests work with the Monocle Platform.
It first copies the extensions from the JDK to the target/java-extensions folder.
Then copies the openjfx-monocle implementation to the same folder.
Afterwards it sets the extensions path to the folder with the copied extensions and the monocle platform.
-->
<profile>
<id>headless-tests</id>
<activation>
<property>
<name>headless.tests</name>
<value>true</value>
</property>
</activation>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-external-jars</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/java-extensions</outputDirectory>
<resources>
<resource>
<directory>${java.home}/lib/ext/</directory>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-monocle-to-extensions</id>
<phase>generate-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/java-extensions</outputDirectory>
<resources>
<resource>
<directory>src/test/resources/test-lib</directory>
<includes>
<include>openjfx-monocle-8u76-b04.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<argLine>-Djava.ext.dirs=${project.basedir}/target/java-extensions</argLine>
</configuration>
</plugin>
</plugins>
</build>
</profile>
就我而言,我从 maven 复制了 monocle jar 到 src/test/resources
文件夹中。这可以通过使用 Maven Dependency Plugin 进一步改进直接使用 maven 复制 monocle jar,而不是将其放在 src/test/resources
中。
关于java - Maven 和 Java 扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52488363/