【发布时间】:2021-10-20 21:39:19
【问题描述】:
我已将我的 JDK 升级到版本 17。 现在,当我尝试使用在 Quarkus 上运行的 optaplanner 运行参数化单元测试时,我得到以下堆栈跟踪:
java.lang.ExceptionInInitializerError
Caused by: java.lang.reflect.InaccessibleObjectException: Unable to make field private transient java.util.NavigableMap java.util.TreeSet.m accessible: module java.base does not "opens java.util" to unnamed module @724b93a8
[ERROR] org.m.s.c.score.constraints.SecConflictTest.secConflictTest(String, int, Agent)[2] Time elapsed: 0.011 s <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class com.thoughtworks.xstream.converters.collections.TreeSetConverter$Reflections
[ERROR] org.m.s.c.score.constraints.SecConflictTest.secConflictTest(String, int, Agent)[3] Time elapsed: 0.014 s <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class com.thoughtworks.xstream.converters.collections.TreeSetConverter$Reflections
在阅读了有关此类问题的一些信息后,我添加了
--add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED
在以下部分中我的 Maven POM:Quarkus-maven-plugin config 和 maven-surefire-config
<plugins>
<plugin>
<groupId>${quarkus.platform.group-id}</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<version>${quarkus.platform.version}</version>
<extensions>true</extensions>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<compilerArgs>
<arg>--enable-preview --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED</arg>
</compilerArgs>
<jvmArgs>--enable-preview --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED</jvmArgs>
</configuration>
<executions>
<execution>
<goals>
<goal>build</goal>
<goal>generate-code</goal>
<goal>generate-code-tests</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${compiler-plugin.version}</version>
<configuration>
<parameters>${maven.compiler.parameters}</parameters>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<argLine>
--add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED
</argLine>
<systemPropertyVariables>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</plugin>
</plugins>
并在配置文件本机的 maven-failsafe-plugin 配置中:
<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<argLine>
--add-opens java.base/java.lang.reflect=ALL-UNNAMED
--add-opens java.base/java.util=ALL-UNNAMED
--add-opens java.base/java.text=ALL-UNNAMED
--add-opens java.desktop/java.awt.font=ALL-UNNAMED
</argLine>
<systemPropertyVariables>
<native.image.path>${project.build.directory}/${project.build.finalName}-runner</native.image.path>
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
<maven.home>${maven.home}</maven.home>
</systemPropertyVariables>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
</profile>
</profiles>
它确实按预期工作:测试运行良好,但我“丢失”了 quarkus 的实时重新加载功能 如果我更改代码中的任何内容并再次调用 WS,则会出现以下错误:
Error restarting Quarkus
java.lang.IllegalArgumentException: error: invalid flag: --enable-preview --add-opens
java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens
java.base/java.text=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED
我正在寻找一种配置,允许 Quarkus 与 Optaplanner 在 Java 17 上运行,ParmetizedTests 运行良好并且实时重新加载仍然有效。
有关信息,通过简单的测试(无参数化),它确实可以在没有特定 --add-open 配置的情况下工作。
这是引导我进行第一次修复的帖子: https://github.com/quarkusio/quarkus/issues/10303#issuecomment-666492921
【问题讨论】:
-
这个问题恐怕与OptaPlanner或Quarkus都无关。进行这些非法反射调用的是 XStream——避免这些调用的方法是不使用 XStream。欢迎您使用 OptaPlanner 支持的其他持久化机制,例如 JAXB、JSON 等。
-
@LukášPetrovicý 感谢您的评论,我会尝试并让您知道 :)
-
您使用的是哪个版本的 OptaPlanner 和 Quarkus?
-
@GeoffreyDeSmet 对于 quarkus 是 2.3.0.Final 对于 optaplanner 它是 8.11.1.Final
标签: java quarkus optaplanner