Skip to content
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

Support java 9 projects #282

Closed
RyanBard opened this issue Nov 18, 2017 · 10 comments
Closed

Support java 9 projects #282

RyanBard opened this issue Nov 18, 2017 · 10 comments

Comments

@RyanBard
Copy link
Contributor

When #259 was fixed, it only verified that jjwt itself can be built with Java 9 (but targeting an older version of java). It did not address the problem of using jjwt in a project that is targeting Java 9.

You can see the problem in jjwt by modifying the <jdk.version> to 1.9 and trying to build:

diff --git a/pom.xml b/pom.xml
index 1c34c5b..02e3f5a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -81,7 +81,7 @@
         <maven.jar.version>3.0.2</maven.jar.version>
         <maven.compiler.version>3.6.1</maven.compiler.version>
 
-        <jdk.version>1.7</jdk.version>
+        <jdk.version>1.9</jdk.version>
         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
         <buildNumber>${user.name}-${maven.build.timestamp}</buildNumber>
 
Apache Maven 3.5.2 (138edd61fd100ec658bfa2d307c43b76940a5d7d; 2017-10-18T03:58:13-04:00)
Maven home: /Users/ryan/.m2/wrapper/dists/apache-maven-3.5.2-bin/28qa8v9e2mq69covern8vmdkj0/apache-maven-3.5.2
Java version: 9.0.1, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.13.1", arch: "x86_64", family: "mac"
[INFO] --- maven-compiler-plugin:3.6.1:compile (default-compile) @ jjwt ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 81 source files to /Users/ryan/projects/java/jjwt/target/classes
[INFO] /Users/ryan/projects/java/jjwt/src/main/java/io/jsonwebtoken/lang/Classes.java: Some input files use or override a deprecated API.
[INFO] /Users/ryan/projects/java/jjwt/src/main/java/io/jsonwebtoken/lang/Classes.java: Recompile with -Xlint:deprecation for details.
[INFO] /Users/ryan/projects/java/jjwt/src/main/java/io/jsonwebtoken/lang/RuntimeEnvironment.java: Some input files use unchecked or unsafe operations.
[INFO] /Users/ryan/projects/java/jjwt/src/main/java/io/jsonwebtoken/lang/RuntimeEnvironment.java: Recompile with -Xlint:unchecked for details.
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /Users/ryan/projects/java/jjwt/src/main/java/io/jsonwebtoken/impl/Base64Codec.java:[21,25] package javax.xml.bind is not visible
  (package javax.xml.bind is declared in module java.xml.bind, which is not in the module graph)
[ERROR] /Users/ryan/projects/java/jjwt/src/main/java/io/jsonwebtoken/impl/Base64Codec.java:[26,25] package javax.xml.bind is not visible
  (package javax.xml.bind is declared in module java.xml.bind, which is not in the module graph)
[INFO] 2 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 4.205 s
[INFO] Finished at: 2017-11-18T14:57:44-05:00
[INFO] Final Memory: 26M/86M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.6.1:compile (default-compile) on project jjwt: Compilation failure: Compilation failure: 
[ERROR] /Users/ryan/projects/java/jjwt/src/main/java/io/jsonwebtoken/impl/Base64Codec.java:[21,25] package javax.xml.bind is not visible
[ERROR]   (package javax.xml.bind is declared in module java.xml.bind, which is not in the module graph)
[ERROR] /Users/ryan/projects/java/jjwt/src/main/java/io/jsonwebtoken/impl/Base64Codec.java:[26,25] package javax.xml.bind is not visible
[ERROR]   (package javax.xml.bind is declared in module java.xml.bind, which is not in the module graph)
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

I have also created a project that uses jjwt and shows the problem referenced in #259: https://github.com/RyanBard/jjwt-consumer-example

The problem is that Java 9 has deprecated jaxb and it requires extra flags to include that module. If I understand correctly, jaxb will probably be completely removed in Java 10, so it seems like the best solution is to explicitly depend on jaxb. This should make it easier for jjwt to target multiple versions of java without having to build multiple artifacts with different classifiers.

RyanBard added a commit to RyanBard/jjwt that referenced this issue Nov 18, 2017
This adds an explicit jaxb dependency to fix consuming projects that build with
and target java 9.
@Spenhouet
Copy link

I can't build my project because of this issue.

@RyanBard
Copy link
Contributor Author

@Spenhouet

You can add an explicit dependency on jaxb-api to your project until jjwt adds the dependency or removes the usage of jaxb classes:

https://github.com/jwtk/jjwt/pull/283/files

@househacker
Copy link

Any advice on how to configure this same workaround for a Java 9 proejct built with ant?
I have tried the --add-modules java.xml.bind







@Spenhouet
Copy link

When will the commit from @RyanBard be merged and when will there be a Java 9 compatible release?

@RyanBard
Copy link
Contributor Author

RyanBard commented Mar 2, 2018

@househacker, I haven't used ant in a long time, but I assume you can just specify the dependency information from maven (groupId=javax.xml.bind, artifactId=jaxb-api, version=2.3.0) if you use something like ivy.

Otherwise, you can download the jar out of the maven repo and include it in your projects' lib dir or something:

@househacker
Copy link

Thanks, I had success with the brute force setting: --add-modules java.se.ee

<target name="compile" depends="jooq">
    <echo>Compiling source code with:</echo>
    <echo>Java/JVM detail version: ${java.version}</echo>
    <javac executable="/Library/Java/JavaVirtualMachines/jdk-9.0.1.jdk/Contents/Home/bin/javac" srcdir="${basedir}/src" destdir="${build}/classes" listfiles="yes" debug="true"
           debuglevel="lines,vars,source">
        <compilerarg line="--add-modules java.se.ee" />
        <classpath>
            <path refid="compile.classpath"/>
        </classpath>
        <include name="**/*.java"/>
    </javac>
</target>

@lhazlewood
Copy link
Contributor

@RyanBard thanks for your help/input in this. The JAXB import was provided only because that was guaranteed to work in JDK 7 and 8 environments using the same code. The real solution to this problem is basically to detect if using JDK 8 and above, and if so, use the JDK's native Base64 encoder/decoder, and if on JDK 7, use the JAXB APIs. That said, we probably won't support JDK 7 for too much longer.

@lhazlewood
Copy link
Contributor

@RyanBard I think we need to modify https://github.com/jwtk/jjwt/blob/master/src/main/java/io/jsonwebtoken/impl/DefaultTextCodecFactory.java to check for the presence of java.util.Base64, and if available, use that. It's available on later Android SDKs as well as JDK 8.

We'll still need to fall back to either the previous native Android codec or the JAXB api depending on if java.util.Base64 is not available and depending on the runtime environment.

@RyanBard
Copy link
Contributor Author

RyanBard commented Jul 5, 2018

I'll try that out some time tonight.

@lhazlewood
Copy link
Contributor

Closing as a duplicate of #333. Work will be tracked via that issue and we hope to have that released asap in the coming days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants