JUnit 5, Java 9 and Gradle: How to pass --add-modules?
According to Alan Bateman, I added the following lines to build.gradle
so that gradle bootRun
also works:
runtime('org.glassfish.jaxb:jaxb-runtime:2.3.0', 'javax.activation:activation:1.1.1')
How to run code that uses JAXB under Java 1.9 when deployed via Java Web Start
Per the Modules Shared with Java EE Not Resolved by Default section of the Java 9 migration doc --add-modules
is a workaround because JAXB is being removed from the JDK in the future. So to solve this I just included the JAXB API and an implementation on my classpath, using ANT+Ivy this configuration got me what I needed:
<dependency org="org.glassfish.jaxb" name="jaxb-runtime" rev="2.3.0"/>
<dependency org="org.glassfish.jaxb" name="jaxb-core" rev="2.3.0"/>
<dependency org="javax.xml.bind" name="jaxb-api" rev="2.3.0"/>
<dependency org="javax.activation" name="activation" rev="1.1.1"/>
A few transitive dependencies came along with it (FastInfoset, istack-commons, stax-ex, and txw2). These are desktop swing applications so I like keeping the jar file as small as feasible, after pack200 compression it only added about 600K to my fat jar.
The glassfish implementation does result in an illegal reflective access warning from Java 9. I assume an update will come out soon that doesn't use illegal reflection.
How to get access to javax.annotation.Resource at run time in Java 9
Just to clear out some confusion here. The ways to work stated in the question by you are alternatives and should not be combined as you have already seen.
the unnamed module reads package javax.annotation from both
java.xml.ws.annotation and java.annotation
So the way it would work is either:
You can use the compiler args to add modules
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<release>9</release>
<compilerArgs>
<arg>--add-modules</arg>
<arg>java.xml.ws.annotation</arg>
</compilerArgs>
</configuration>
</plugin>
OR
Make use of the javax.xml.ws.annotation
being an upgradeable module which is when you can make use of the dependency
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.1</version>
</dependency>
Ideally this would be a preferrable option to stick to as the former is just an alternate to use the @Deprecated module marked forRemoval
.
So the required clause by itself it not enough to get access to a
module... is this true for all JDK-supplied modules (excluding
java.base), or it is only true for deprecated modules?
No, the requires
is just a part of declaration. [Think about this, prior to JDK 9 if you used a statement import some.foo.bar;
in your class which was not added as a library(classpath) would that have worked?]. The module marked as required has to be on the modulepath for you to access it.
Update - The first option would not be supported any time longer with the use of JDK/11 or above wherein the JEP to Remove the Java EE and CORBA Modules is targetted.
add-modules only on compilation
I made this answer a while ago where I answered this as an additional info to exposing non java.se
packages in Java-9 using Maven.
The added part specifically focusses on using the standalone version of the java.xml.*
APIs. To adapt to which you can probably start consuming the dependency on jaxb-api:2.3.0
which can be loaded as a module and can be executed from the classpath as well. The change you need to make is to add the following to your dependencies list:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
This way you ensure migrating to standalone APIs for the module as well as moving away from a deprecated piece of code.
jooq-codegen-maven plugin and JDK9 compilation error
Version 3.10.0 - September 29, 2017
Just to mark this up to the date, you can now use JOOQ
library version 3.10.0
.
..is the first release that is formally integration tested with Java 9
along with the existing integration tests for Java 6/7 and for Java 8.
To use jOOQ with Java 9 use the Java 8 distribution which has not yet
been modularised, but contains Automatic-Module-Name specification to
be forward compatible with future, modularised jOOQ distributions.
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<version>3.10.0</version>
...
</plugin>
Crash Ropeytask with Java 9
This is covered in the Modules Shared with Java EE Not Resolved by Default section of the JDK 9 Migration Guide. You should find it works find once you put the JAXB API and implementation on the class path.
Related Topics
Performance of Javafx Gui VS Swing
Jtable Won't Show Column Headers
Sorting a List with Stream.Sorted() in Java
How to Set Working Directory with Processbuilder
Java's Date(...) Constructor Is Deprecated; What Does That Mean
Singleton Design Pattern: Pitfalls
Comparing Stringbuffer Content with Equals
Is There a Difference in Removing the Curly Braces from If Statements in Java
Simple Way to Count Character Occurrences in a String
Why Do I Get "Non-Static Variable This Cannot Be Referenced from a Static Context"
Understanding Logic in Caseinsensitivecomparator
Making Distinctions Between Different Kinds of Jsf Managed-Beans
Gson Custom Seralizer for One Variable (Of Many) in an Object Using Typeadapter
Mockito: Invaliduseofmatchersexception
Rotating Bufferedimage Instances