Skip to content

Support Java 9 #7226

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
snicoll opened this issue Oct 26, 2016 · 26 comments
Closed
3 tasks done

Support Java 9 #7226

snicoll opened this issue Oct 26, 2016 · 26 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@snicoll
Copy link
Member

snicoll commented Oct 26, 2016

Spring Boot master (2.0.0.BUILD-SNAPSHOT) doesn't currently build with JDK9, see the dedicated job

@snicoll snicoll added for: team-attention An issue we'd like other members of the team to review and removed for: team-attention An issue we'd like other members of the team to review labels Oct 26, 2016
@snicoll
Copy link
Member Author

snicoll commented Oct 26, 2016

The current build doesn't exhibit the same issue. I'll investigate that a bit more.

@snicoll snicoll self-assigned this Oct 26, 2016
@snicoll snicoll modified the milestones: 2.0.0.M1, 2.0.0.RC1 Oct 26, 2016
@snicoll
Copy link
Member Author

snicoll commented Oct 31, 2016

We need to find a different way to extract the default values for the meta-data as we're using a proprietary API.

java.lang.IllegalAccessException: class org.springframework.boot.configurationprocessor.fieldvalues.javac.Trees cannot access class com.sun.tools.javac.api.JavacTrees (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.api to unnamed module @5a7fe64f

@snicoll
Copy link
Member Author

snicoll commented Oct 31, 2016

[ERROR] /Users/snicoll/workspace/pivotal/spring-boot/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/tunnel/server/RemoteDebugPortProvider.java:[51,43] cannot find symbol
  symbol:   class VMSupport
  location: package sun.misc

@philwebb
Copy link
Member

philwebb commented Nov 1, 2016

java.lang.IllegalAccessException: class org.springframework.boot.configurationprocessor.fieldvalues.javac.Trees cannot access class com.sun.tools.javac.api.JavacTrees (in module jdk.compiler) because module jdk.compiler does not export com.sun.tools.javac.api to unnamed module @5a7fe64f

Yikes, this might be an issue. It might be worth asking on the JDK mailing list if there's any official way to do this.

@philwebb philwebb added the for: team-attention An issue we'd like other members of the team to review label Nov 1, 2016
@snicoll snicoll removed the for: team-attention An issue we'd like other members of the team to review label Nov 2, 2016
@snicoll
Copy link
Member Author

snicoll commented Nov 28, 2016

I've created a thread on jigsaw-dev about this.

snicoll added a commit that referenced this issue Nov 28, 2016
Cast runtime object retrieved reflectively to their public interface
counterpart.

See gh-7226
@snicoll snicoll changed the title Fix master build with JDK9 Support Java 9 Dec 5, 2016
@snicoll
Copy link
Member Author

snicoll commented Dec 5, 2016

There are also additional runtime issues (see #7565 for more details)

@snicoll snicoll added priority: high type: enhancement A general enhancement labels Jan 11, 2017
@philwebb philwebb modified the milestones: 2.0.0.RC1, 2.0.0 Jan 12, 2017
@snicoll snicoll added the for: team-attention An issue we'd like other members of the team to review label Feb 6, 2017
@snicoll
Copy link
Member Author

snicoll commented Feb 6, 2017

LaunchedURLClassLoaderTests#resolveFromNested does not work with Java9 since nested.jar!/3.dat isn't identified as a valid resource anymore. I haven't found any information about this yet.

@snicoll
Copy link
Member Author

snicoll commented Feb 6, 2017

IJ also (wrongly) refuses to compile SignalUtils. I've reported IDEA-167758

@wilkinsona
Copy link
Member

LaunchedURLClassLoaderTests#resolveFromNested fails because org.springframework.boot.loader.jar.Handler isn't being used. This is the class that we configure to be the URLStreamHandler for jar: URLs. Unfortunately, this due to an optimisation for jar:file: URLs. It creates a java.util.jar.JarFile directly from a File rather than going via a JarURLConnection. Similar logic appears to be in Java 8 so it's not yet clear why the behaviour has changed.

@snicoll
Copy link
Member Author

snicoll commented Jun 16, 2017

Ok we're further now. Next is we need to switch to Maven assembly plugin 3.0.1 but we need to make the release happen first. I am on it.

@snicoll snicoll modified the milestones: 2.0.0.M3, 2.0.0.M4 Jul 13, 2017
@wilkinsona wilkinsona modified the milestones: 2.0.0.M5, 2.0.0.M4 Jul 28, 2017
@robinst
Copy link

robinst commented Sep 22, 2017

Friendly ping :). What's the status of this?

@douglarek
Copy link

Will Spring boot 1.5.x support java 9 ?

@wilkinsona
Copy link
Member

@douglarek No

@wilkinsona
Copy link
Member

wilkinsona commented Sep 22, 2017

@robinst The status is all on this page. The issue is open and scheduled for 2.0 M5.

@juanmbellini
Copy link

Don't know if this comment should be here or where, but I have just upgrade to java 9 and couldn't run a Spring Boot Application.
This is a Spring Boot Application using Jersey, Data and Security starters.

First of all the following was printed in the console when trying to run the app.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by ...to field ...
WARNING: Please consider reporting this to the maintainers of  org.springframework.cglib.core.ReflectUtils$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

Then the app didn't start, printing the following stacktrace

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.autoconfigure.jersey.ResourceConfigCustomizer]: Factory method 'resourceConfigCustomizer' threw exception; nested exception is java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189)
	at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588)
	... 57 common frames omitted
Caused by: java.lang.NoClassDefFoundError: javax/xml/bind/annotation/XmlElement
	at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:139)
	at com.fasterxml.jackson.module.jaxb.JaxbAnnotationIntrospector.<init>(JaxbAnnotationIntrospector.java:126)
	at org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$JacksonResourceConfigCustomizer$ObjectMapperCustomizer.addJaxbAnnotationIntrospector(JerseyAutoConfiguration.java:266)
	at org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$JacksonResourceConfigCustomizer$ObjectMapperCustomizer.access$200(JerseyAutoConfiguration.java:262)
	at org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$JacksonResourceConfigCustomizer.addJaxbAnnotationIntrospectorIfPresent(JerseyAutoConfiguration.java:258)
	at org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$JacksonResourceConfigCustomizer.resourceConfigCustomizer(JerseyAutoConfiguration.java:244)
	at org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$JacksonResourceConfigCustomizer$$EnhancerBySpringCGLIB$$a15c1d0c.CGLIB$resourceConfigCustomizer$0(<generated>)
	at org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$JacksonResourceConfigCustomizer$$EnhancerBySpringCGLIB$$a15c1d0c$$FastClassBySpringCGLIB$$3126cdea.invoke(<generated>)
	at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
	at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:358)
	at org.springframework.boot.autoconfigure.jersey.JerseyAutoConfiguration$JacksonResourceConfigCustomizer$$EnhancerBySpringCGLIB$$a15c1d0c.resourceConfigCustomizer(<generated>)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:564)
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
	... 58 common frames omitted
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.annotation.XmlElement
	at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
	at org.springframework.boot.loader.LaunchedURLClassLoader.loadClass(LaunchedURLClassLoader.java:94)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
	... 74 common frames omitted

Making some research on google I found that Java EE modules must be explicitly included, so I created the module-info.java file, including the corresponding module. But after that, any class of Spring couldn't be located.

@cemo
Copy link
Contributor

cemo commented Sep 23, 2017

@juanmbellini There are multiple ways to fix this issue but I preferred explicitly declaring these dependencies in my project.

    <jaxb.version>2.3.0</jaxb.version>
    <jaxws.version>2.3.0</jaxws.version>

and

      <dependency>
        <groupId>javax.annotation</groupId>
        <artifactId>javax.annotation-api</artifactId>
        <version>${javax-annotation.version}</version>
      </dependency>
      <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>${jaxb.version}</version>
      </dependency>
      <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>${jaxb.version}</version>
      </dependency>
      <dependency>
        <groupId>javax.xml.ws</groupId>
        <artifactId>jaxws-api</artifactId>
        <version>${jaxws.version}</version>
      </dependency>
      <dependency>
        <groupId>com.sun.xml.ws</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>${jaxws.version}</version>
      </dependency>

As you stated these modules are part of java ee and will be removed in the future. In the future you will need to definitely add these dependencies.

I have not tested in a detailed way but spring boot 1.5.x seems working with JDK9 as well. Please note that I have not added module info files yet. I had just added some dependencies.

@vnobo
Copy link

vnobo commented Sep 25, 2017

spring support java 9 ,It will take some time to support! so wait wait wait.....

@snicoll
Copy link
Member Author

snicoll commented Sep 25, 2017

One important piece at this point is to update AspectJ as 1.9 is not GA yet and is definitely required to run with Java 9

<aspectj.version>1.9.0.BETA-7</aspectj.version>

(available from repo.spring.io/milestone)

@snicoll
Copy link
Member Author

snicoll commented Sep 26, 2017

Unless we manage to get a workaround, it looks like there is a bug in Maven that prevents us to property test with Java9. I've opened SUREFIRE-1424.

snicoll added a commit that referenced this issue Sep 26, 2017
This commit workarounds a bug in Surefire, see
https://issues.apache.org/jira/browse/SUREFIRE-1424

It also adds `javax.xml.bind` as it is no longer provided by default
with Java9

See gh-7226
@snicoll
Copy link
Member Author

snicoll commented Sep 27, 2017

Liquibase does not work with Java9 yet. I've created CORE-3114

wilkinsona added a commit that referenced this issue Sep 28, 2017
The translations for the timezone names vary between Java 8 and Java
9. For example, with Java 9, UTC's name is no longer localized while
others have different localizations. This commit updates the test
to verify that the correct locale is being used while also tolerating
the different localization's of Java 8 and 9.

See gh-7226
snicoll added a commit that referenced this issue Sep 28, 2017
@snicoll
Copy link
Member Author

snicoll commented Sep 29, 2017

With well identified limitations the build now passes with Java 9. I've started a wiki page to gathers some of the gotchas.

@snicoll snicoll closed this as completed Sep 29, 2017
@juliuskrah
Copy link

@juanmbellini you can try by adding the modules.

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <configuration>
    <jvmArguments>--add-modules java.xml.bind,java.xml.ws,java.xml.ws.annotation</jvmArguments>
  </configuration>
</plugin>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

9 participants