Reputation: 109
Im creating a simple test app with Java11 to learn JPA, Hibernate, some java modularity and later on (CDI with dagger), and im having problems compiling when i use a module-info.java
I got a few DAO repositories done for a few simple classes that are JPA annotated to test it out and everything works perfect on my Main class where i insert and retrieve some objects succesfully. Note: up until this point I have no module-info.java
Now im making some FXMLs (with scenebuilder). I have done this before and i have had to create a module-info.java to resolve some JavaFX issues (that i believe have to do with java reflection): I did this in this other project and works as expected. That was generated by Intellij warnings being resolved either by IntelliJ resolving them or some RunTime Exception informing me that package app.a needs to open to package app.b and me doing that manually. This was my first experience with module-info.java
So when i try to run with gui through another class MainFX i get some errors (that i will try to solve but its not what this question is about):
Caused by: java.lang.IllegalAccessError: class com.sun.javafx.fxml.FXMLLoaderHelper (in unnamed module @0x71b9e075) cannot access class com.sun.javafx.util.Utils (in module javafx.graphics) because module javafx.graphics does not export com.sun.javafx.util to unnamed module @0x71b9e075
at com.sun.javafx.fxml.FXMLLoaderHelper.<clinit>(FXMLLoaderHelper.java:38)
at javafx.fxml.FXMLLoader.<clinit>(FXMLLoader.java:2056)
at app.control.MainControl.loadFXML(MainControl.java:22)
at app.MainFX.start(MainFX.java:42)
It is at this point that i tried to add a module-info.java and resolved all import dependencies caught by IntelliJ adding some of my module dependencies:
module bartest {
requires com.google.common;
requires javafx.controls;
requires javafx.graphics;
requires javafx.fxml;
requires flogger;
requires java.logging;
requires java.persistence;
opens app;
}
but with any thing i have tried i get a java.lang.module.ResolutionException
Information:java: compiler message file broken: key=compiler.misc.msg.bug arguments=11.0.4, {1}, {2}, {3}, {4}, {5}, {6}, {7}
Information:java: java.lang.module.ResolutionException: Module jakarta.activation contains package javax.activation, module java.activation exports package javax.activation to jakarta.activation
Information:java: at java.base/java.lang.module.Resolver.resolveFail(Resolver.java:885)
Information:java: at java.base/java.lang.module.Resolver.failTwoSuppliers(Resolver.java:789)
Information:java: at java.base/java.lang.module.Resolver.checkExportSuppliers(Resolver.java:718)
Information:java: at java.base/java.lang.module.Resolver.finish(Resolver.java:362)
Information:java: at java.base/java.lang.module.Configuration.<init>(Configuration.java:130)
Information:java: at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:484)
Information:java: at java.base/java.lang.module.Configuration.resolveAndBind(Configuration.java:288)
Information:java: at jdk.compiler/com.sun.tools.javac.file.JavacFileManager.getServiceLoader(JavacFileManager.java:985)
Information:java: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Information:java: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Information:java: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Information:java: at java.base/java.lang.reflect.Method.invoke(Method.java:566)
Information:java: at org.jetbrains.jps.javac.JavacMain$2.invoke(JavacMain.java:290)
Information:java: at com.sun.proxy.$Proxy24.getServiceLoader(Unknown Source)
Information:java: at com.sun.proxy.$Proxy25.getServiceLoader(Unknown Source)
Information:java: at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.initProcessorLoader(JavacProcessingEnvironment.java:261)
Information:java: at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.<init>(JavacProcessingEnvironment.java:237)
Information:java: at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment.instance(JavacProcessingEnvironment.java:193)
Information:java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.initProcessAnnotations(JavaCompiler.java:1136)
Information:java: at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.compile(JavaCompiler.java:922)
Information:java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.lambda$doCall$0(JavacTaskImpl.java:104)
Information:java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.handleExceptions(JavacTaskImpl.java:147)
Information:java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.doCall(JavacTaskImpl.java:100)
Information:java: at jdk.compiler/com.sun.tools.javac.api.JavacTaskImpl.call(JavacTaskImpl.java:94)
Information:java: at org.jetbrains.jps.javac.JavacMain.compile(JavacMain.java:195)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compileJava(JavaBuilder.java:460)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.compile(JavaBuilder.java:330)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.doBuild(JavaBuilder.java:255)
Information:java: at org.jetbrains.jps.incremental.java.JavaBuilder.build(JavaBuilder.java:213)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runModuleLevelBuilders(IncProjectBuilder.java:1324)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuildersForChunk(IncProjectBuilder.java:1004)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildTargetsChunk(IncProjectBuilder.java:1071)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunkIfAffected(IncProjectBuilder.java:965)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.buildChunks(IncProjectBuilder.java:794)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.runBuild(IncProjectBuilder.java:376)
Information:java: at org.jetbrains.jps.incremental.IncProjectBuilder.build(IncProjectBuilder.java:178)
Information:java: at org.jetbrains.jps.cmdline.BuildRunner.runBuild(BuildRunner.java:139)
Information:java: at org.jetbrains.jps.cmdline.BuildSession.runBuild(BuildSession.java:288)
Information:java: at org.jetbrains.jps.cmdline.BuildSession.run(BuildSession.java:121)
Information:java: at org.jetbrains.jps.cmdline.BuildMain$MyMessageHandler.lambda$channelRead0$0(BuildMain.java:228)
Information:java: at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
Information:java: at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
Information:java: at java.base/java.lang.Thread.run(Thread.java:834)
Information:java: Errors occurred while compiling module 'bartest'
Information:javac 11.0.4 was used to compile java sources
Information:29/08/2019 4:03 a. m. - Build completed with 1 error and 0 warnings in 4 s 405 ms
Error:java: Compilation failed: internal java compiler error
The moment I delete the module-info.java i start getting succesfull Build and non javaFX code works fine. im guessing without the module-info.java, module-info gets auto generated correctly.
so with my module-info.java it cant compile, without it does compile but I cant run JavaFX that probably can be solved without the module-info.java file, but i would like to know what is causing this, also as you can tell im fairly new to most of this concepts (maven, jpa, modularity) my goal for this test is to learn, all help will be appreciated.
other things i think could be affecting are my lack of experience with maven pom.xml files, i basicly let Intellij generate dependencies and plugins tags i search for internet but may be wrong
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<artifactId>bartest</artifactId>
<groupId>com.kurama</groupId>
<modelVersion>4.0.0</modelVersion>
<version>1.0-SNAPSHOT</version>
<name>J_HibernateDaggerTest</name>
<url>http://maven.apache.org</url>
<properties>
<java.version>11.0.4</java.version>
<hibernate.version>5.3.11.Final</hibernate.version>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<release>${java.version}</release>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<groupId>org.apache.maven.plugins</groupId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<configuration>
<mainClass>app.MainFX</mainClass>
</configuration>
<version>0.0.3</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>6.2</version>
</dependency>
</dependencies>
<configuration>
<forkCount>0</forkCount>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<artifactId>javafx-controls</artifactId>
<groupId>org.openjfx</groupId>
<version>11.0.2</version>
</dependency>
<dependency>
<artifactId>javafx-fxml</artifactId>
<groupId>org.openjfx</groupId>
<version>11.0.2</version>
</dependency>
<dependency>
<artifactId>guava</artifactId>
<groupId>com.google.guava</groupId>
<version>LATEST</version>
</dependency>
<dependency>
<artifactId>mariadb-java-client</artifactId>
<groupId>org.mariadb.jdbc</groupId>
<version>2.4.2</version>
</dependency>
<dependency>
<artifactId>flogger</artifactId>
<groupId>com.google.flogger</groupId>
<version>0.4</version>
</dependency>
<dependency>
<artifactId>flogger-system-backend</artifactId>
<groupId>com.google.flogger</groupId>
<version>0.4</version>
</dependency>
<dependency>
<artifactId>controlsfx</artifactId>
<groupId>org.controlsfx</groupId>
<version>11.0.0</version>
</dependency>
<dependency>
<artifactId>jfxtras-controls</artifactId>
<groupId>org.jfxtras</groupId>
<version>10.0-r1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${hibernate.version}</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
</dependencies>
</project>
Edit 1:
HERE user Gili pointed out that:
"Eclipse foundation has taken over JavaEE development.
javax.activation
has moved tojakarta.activation
per wiki.eclipse.org/New_Maven_Coordinates"
so i tried adding to my pom the following deps
<dependency>
<groupId>jakarta.activation</groupId>
<artifactId>jakarta.activation-api</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>2.2.2</version>
</dependency>
<dependency>
<groupId>jakarta.transaction</groupId>
<artifactId>jakarta.transaction-api</artifactId>
<version>1.3.1</version>
</dependency>
and on build it still fails and i get a warning on the module-info file
Error:java: java.lang.module.ResolutionException: Modules java.activation and jakarta.activation export package javax.activation to module error.prone.annotations
Information:java: java.lang.module.ResolutionException: Modules jakarta.activation and java.activation export package javax.activation to module javafx.webEmpty
Information:java: Errors occurred while compiling module 'bartest'
Information:javac 11.0.4 was used to compile java sources
Information:29/08/2019 4:03 a. m. - Build completed with 1 error and 0 warnings in 4 s 405 ms
Error:java: Compilation failed: internal java compiler error
EDIT 2:
I did follow IntelliJ can't recognize JavaFX 11 with OpenJDK 11
that led me to running JavaFX projects before, but the moment I add the module-info.java as told there, i get the exception pasted above. on build. clearly there is some issue with Modules jakarta.activation
and java.activation
both exporting package javax.activation
but i have no idea how to resolve this
Upvotes: 5
Views: 15468
Reputation: 109
This patching up code mat have caught up with me... ill explain here for documentation reasons
Following https://stackoverflow.com/a/48136912/11970095 i added
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
</dependency>
removing this fixed the big problem, only thing missing was the module-info.java that after fixing required modules now looks like this
module bartest {
requires com.google.common;
requires javafx.controls;
requires javafx.graphics;
requires javafx.fxml;
requires flogger;
requires java.logging;
requires net.bytebuddy;
requires java.sql;
requires java.xml.bind;
opens app.control to javafx.fxml;
opens app.model to org.hibernate.orm.core;
opens app;
}
and everything works fine now.
Upvotes: 5