Java 17 preview features in WAR

380 views
Skip to first unread message

Nir Lisker

unread,
Oct 4, 2021, 12:23:03 AM10/4/21
to WildFly
Hi,

I'm using Wildfly 23.0.2Final. I am trying to deploy a WAR that uses Java 17 with preview features.

In the pom.xml of the WAR project I specify
<compilerVersion>17</compilerVersion>
<compilerArgs>
<arg>--enable-preview</arg>
</compilerArgs>

If I run "maven clean verify" then the build is successful with Java 17 preview features.

I'm running Wildfly inside Eclipse with the JBoss tools (I can detail all the installed plugins if needed). It is configured to use Java 17 as its execution environment.
In the launch configuration, I added --enable-preview in the VM arguments. The full VM arguments section is:

"-Dprogram.name=JBossTools: WildFly 23 Game" -server -Xms64m -Xmx512m -Dorg.jboss.resolver.warning=true -Djava.net.preferIPv4Stack=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Djboss.modules.system.pkgs=org.jboss.byteman -Djava.awt.headless=true "-Dorg.jboss.boot.log.file=C:\Program Files\wildfly-23.0.2.Final\standalone\log\boot.log" "-Dlogging.configuration=file:C:\Program Files\wildfly-23.0.2.Final\standalone\configuration\logging.properties" "-Djboss.home.dir=C:\Program Files\wildfly-23.0.2.Final" -Dorg.jboss.logmanager.nocolor=true --add-exports=java.base/sun.nio.ch=ALL-UNNAMED --add-exports=jdk.unsupported/sun.misc=ALL-UNNAMED --add-exports=jdk.unsupported/sun.reflect=ALL-UNNAMED --add-modules=java.se -Djboss.bind.address.management=localhost --enable-preview 

I then start the server and after some initialization I get

07:05:04,696 WARN  [org.jboss.modules.define] (MSC service thread 1-2) Failed to define class com.project.MyClass in Module "deployment.90af0a56-c4e8-444d-b364-ead0e2958a0d.war" from Service Module Loader: java.lang.UnsupportedClassVersionError: Failed to link com/project/MyClass   (Module "deployment.90af0a56-c4e8-444d-b364-ead0e2958a0d.war" from Service Module Loader):  com/project/MyClass   (class file version 60.65535) was compiled with preview features that are unsupported. This version of the Java Runtime only recognizes preview features for class file version 61.65535
at java.base/java.lang.ClassLoader.defineClass1(Native Method)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1012)
at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1090)
at org.jboss.modules.ModuleClassLoader.doDefineOrLoadClass(ModuleClassLoader.java:424)
at org.jboss.modules.ModuleClassLoader.defineClass(ModuleClassLoader.java:555)
at org.jboss.modules.ModuleClassLoader.loadClassLocal(ModuleClassLoader.java:339)
at org.jboss.modules.ModuleClassLoader$1.loadClassLocal(ModuleClassLoader.java:126)
at org.jboss.modules.Module.loadModuleClass(Module.java:753)
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:247)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:410)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:398)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:116)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at org.jbo...@23.0.2.Final//org.jboss.as.ee.utils.ClassLoadingUtils.loadClass(ClassLoadingUtils.java:21)
at org.jbo...@23.0.2.Final//org.jboss.as.ee.utils.ClassLoadingUtils.loadClass(ClassLoadingUtils.java:14)
at org.jbo...@23.0.2.Final//org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.processComponentConfig(InterceptorAnnotationProcessor.java:84)
at org.jbo...@23.0.2.Final//org.jboss.as.ee.component.deployers.InterceptorAnnotationProcessor.deploy(InterceptorAnnotationProcessor.java:77)
at org.jboss...@15.0.1.Final//org.jboss.as.server.deployment.DeploymentUnitPhaseService.start(DeploymentUnitPhaseService.java:182)
at org.jb...@1.4.12.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1739)
at org.jb...@1.4.12.Final//org.jboss.msc.service.ServiceControllerImpl$StartTask.execute(ServiceControllerImpl.java:1701)
at org.jb...@1.4.12.Final//org.jboss.msc.service.ServiceControllerImpl$ControllerTask.run(ServiceControllerImpl.java:1559)
at org.jbos...@2.4.0.Final//org.jboss.threads.ContextClassLoaderSavingRunnable.run(ContextClassLoaderSavingRunnable.java:35)
at org.jbos...@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor.safeRun(EnhancedQueueExecutor.java:1990)
at org.jbos...@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.doRunTask(EnhancedQueueExecutor.java:1486)
at org.jbos...@2.4.0.Final//org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1377)
at java.base/java.lang.Thread.run(Thread.java:833)

For some reason there is a mismatch in the class file version even though everything is set to 17 with preview features.

I'll note that the environment variables JAVA_HOME, JDK_HOME and PATH are still set to 16 because other thing need that, but it looks like everything is running with 17 anyway.
To make sure, I edited the standalone.conf.bat file (I'm on Windows) and uncommented the line
set "JAVA_HOME=C:\Program Files\Java\jdk-17"

I also tried to uncomment the line
set PRESERVE_JAVA_OPTS=true
so the goto won't skip the JAVA_HOME set.

None of this made a difference. When I was doing the same with Java 16 with preview features everything worked fine (without changing the standalone.conf.bat which I tried now only because JAVA_HOME etc. were set to 16).
Is it a problem with Java 17 support? I know that officially it is not supported, but neither is 16 and that was fine.
Did I not compensate properly for the environment variables still being set to 16 and something still uses those?

Thanks,
Nir

Brian Stansberry

unread,
Oct 5, 2021, 8:28:36 PM10/5/21
to WildFly
WildFly 23 won't work well with SE 17. We made a lot of changes between 23 and now related to SE 17 support, including a number of component updates.

To run WF on SE 17 your launch command will need to have the JPMS settings shown at https://github.com/wildfly/wildfly-core/blob/17.0.1.Final/core-feature-pack/common/src/main/resources/content/bin/common.sh#L42. You'll also need to use a config that doesn't include any of the legacy security layer stuff we removed in WF 25.

But even with that I wouldn't expect WF 23 to work well on SE 17. WF 24 might work better, particularly WF Preview 24 which doesn't use legacy security in its standard configs.

WildFly 25 will be out soon and will support SE 17.

Brian Stansberry

unread,
Oct 5, 2021, 11:40:34 PM10/5/21
to WildFly
"Out soon" meaning now. ;)
Reply all
Reply to author
Forward
0 new messages