Environment:
JDK: 10
Maven: 3.5
Maven compiler plugin: 3.7.0
When my project depends on javax.transaction-api:1.2, it does compile without any error. My module-info.java contains:
module my.component {
requires javax.transaction.api;
// other required modules ...
}
However, when my project depends on javax.transaction-api:1.3, the java compiler yields an assertion error. Note that in that case, my module-info.java contains:
module my.component {
requires java.transaction;
// other required modules ...
}
(since the automatic module name of javax.transaction-api is set to java.transaction in the manifest of the 1.3 version)
The assertion error is:
Exception in thread "main" java.lang.AssertionError
at jdk.compiler/com.sun.tools.javac.util.Assert.error(Assert.java:155)
at jdk.compiler/com.sun.tools.javac.util.Assert.check(Assert.java:46)
at jdk.compiler/com.sun.tools.javac.comp.Modules.enter(Modules.java:244)
at jdk.compiler/com.sun.tools.javac.main.JavaCompiler.readSourceFile(JavaCompiler.java:829)
at jdk.compiler/com.sun.tools.javac.processing.JavacProcessingEnvironment$ImplicitCompleter.complete(JavacProcessingEnvironment.java:1506)
at jdk.compiler/com.sun.tools.javac.code.Symbol.complete(Symbol.java:633)
at jdk.compiler/com.sun.tools.javac.code.Symbol$ClassSymbol.complete(Symbol.java:1308)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.complete(Type.java:1139)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.getTypeArguments(Type.java:1065)
at jdk.compiler/com.sun.tools.javac.code.Printer.visitClassType(Printer.java:237)
at jdk.compiler/com.sun.tools.javac.code.Printer.visitClassType(Printer.java:52)
at jdk.compiler/com.sun.tools.javac.code.Type$ClassType.accept(Type.java:992)
at jdk.compiler/com.sun.tools.javac.code.Printer.visit(Printer.java:136)
at jdk.compiler/com.sun.tools.javac.util.AbstractDiagnosticFormatter.formatArgument(AbstractDiagnosticFormatter.java:197)
at jdk.compiler/com.sun.tools.javac.util.AbstractDiagnosticFormatter.formatArguments(AbstractDiagnosticFormatter.java:165)
at jdk.compiler/com.sun.tools.javac.util.BasicDiagnosticFormatter.formatMessage(BasicDiagnosticFormatter.java:111)
at jdk.compiler/com.sun.tools.javac.util.BasicDiagnosticFormatter.formatMessage(BasicDiagnosticFormatter.java:67)
at jdk.compiler/com.sun.tools.javac.util.AbstractDiagnosticFormatter.formatArgument(AbstractDiagnosticFormatter.java:183)
at jdk.compiler/com.sun.tools.javac.util.AbstractDiagnosticFormatter.formatArguments(AbstractDiagnosticFormatter.java:165)
at jdk.compiler/com.sun.tools.javac.util.BasicDiagnosticFormatter.formatMessage(BasicDiagnosticFormatter.java:111)
at jdk.compiler/com.sun.tools.javac.util.BasicDiagnosticFormatter.formatMessage(BasicDiagnosticFormatter.java:67)
at jdk.compiler/com.sun.tools.javac.util.JCDiagnostic.getMessage(JCDiagnostic.java:771)
at jdk.compiler/com.sun.tools.javac.api.ClientCodeWrapper$DiagnosticSourceUnwrapper.getMessage(ClientCodeWrapper.java:799)
This looks like a conflict between the java.transaction module name used by default in the JRE, and the module name declared in the manifest of the javax.transaction-api:1.3 jar file.
Is there a compiler option to prevent this assertion error from occurring?
Related
I have been reading posts in StackOverflow for almost 1 hour and no solutions worked for me.
I am doing a beginner Spring Course using Eclipse and JDK11. And I am having the following error in the terminal:
An error occurred during initialization of boot layer
java.lang.module.FindException: Module proyectoSpringUno not found
this is my java file:
package es.pildoras.IoC;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class UsoEmpleados {
public static void main(String[] args) {
ClassPathXmlApplicationContext contexto = new ClassPathXmlApplicationContext("applicationContext.xml");
Empleados Juan = contexto.getBean("miEmpleado",Empleados.class);
System.out.println(Juan.getTareas());
contexto.close();
}
}
I have an error on the import that says:
The type org.springframework.context.support.ClassPathXmlApplicationContext is not accessible
I know that this error happens because I am using the java module system and if I use java 8, all these issues will disappear, but I am not interested in that solution since I want to learn how to use Spring with newer Java JDKs.
At the moment, I have all my libs added into the Classpath but not into the Modulepath.
Solution I tried:
Adding the libs to the modulepath.
Result: this doesn't work. When I add the libs to the modulepath, Eclipse deletes the libs from the classpath ( probably to avoid duplicates). Now I don't have any issues in the module-info (eclipse inserted automodules) or in the import, but when I launch my app, I have the following error:
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for C:\Users\Stephane\Desktop\curso Spring\ProyectoSpringUno\libs\spring-context-indexer-5.3.6-sources.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class org.springframework.context.index.processor.CandidateComponentsIndexer not in module
this is the module info:
module ProyectoSpringUno {
exports es.pildoras.IoC;
requires spring.context; // this is automaticly added by eclipse when i add libs to the modulepath
}
Resuming
When I add my dependencies to the modulepath, Eclipse don't work because he wants it in the classpath.
When I add my dependencies to the classpath, eclipse say I need to move some dependencies to the modulepath or the module-info will not work.
And eclipse don't let me add them to both modulepath and classpath because they are duplicates.
Any idea on how to fix this?
I have a jar built before Java 9. I'm trying to run a class that is in that jar using Java 9.
From all I read about automatic modules, this should work:
java -p lib/Legacy-1.3.0.jar -m Legacy/com.blah.MyClass
But instead I get this:
Error: Unable to initialize main class com.blah.MyClass in module module Legacy
Caused by: module Legacy: java.lang.NoClassDefFoundError
Yes, com.blah.MyClass is in Legacy. Can I run a class from an automatic module? Why is the word module repeated twice in that error message above?
If I run java --list-modules -p lib/Legacy-1.3.0.jar I see:
Legacy#1.3.0 file://path/to/jar/Legacy-1.3.0.jar automatic
If I run jdeps --generate-module-info . lib/Legacy-1.3.0.jar, I get:
module Legacy {
requires java.logging;
requires transitive java.activation;
requires transitive java.xml;
requires transitive java.xml.bind;
requires transitive java.xml.ws;
exports com.blah;
}
I am trying out the various access rules about who can access and what and I saw this statement in The State of the module system document,
The unnamed module reads every other module. Code in any type loaded from the class path will thus be able to access the exported types of all other readable modules, which by default will include all of the named, built-in platform modules.
So, I wrote the following code to test it out with the following structure:
moduleA/modA.A --> automod/automod.Foo --> nonmodular.Junk --> moduleX/modX.X
Basically,
moduleA's modA.A calls a method on a non-modular class automod.Foo. automod.Foo is packaged into automod.jar and put on the module-path. module-info for moduleA has requires automod; clause. This works fine, as expected.
automod.Foo calls a method on nonmodular.Junk class. nonmodular.Junk is packaged into nonmodular.jar and put on classpath. This works fine, as expected.
nonmodular.Junk calls a method on moduleX's modX.X. modX.X is packaged into moduleX.jar.
It is this step that has a problem. It works if I put moduleX.jar on classpath but not if I put moduleX.jar on module-path. (module-info for moduleX does have exports modX; clause.)
In other words, the following command works:
java --module-path moduleA.jar;automod.jar; -classpath nonmodular.jar;moduleX.jar --module moduleA/modA.A
With the following output:
In modA.A.main() Calling automod.Foo()
In automod.Foo()
In modA.A.main() Calling automod.foo.main()
In automod.Foo.main() Calling nonmodular.Junk()
In automod.Foo.main() Calling nonmodular.Junk.main()
In nonmodular.Junk.main calling new modX.X()
In modX.X()
But the following command doesn't work:
java --module-path moduleA.jar;automod.jar;moduleX.jar -classpath nonmodular.jar; --module moduleA/modA.A
Here is the output:
In modA.A.main() Calling automod.Foo()
In automod.Foo()
In modA.A.main() Calling automod.foo.main()
In automod.Foo.main() Calling nonmodular.Junk()
In automod.Foo.main() Calling nonmodular.Junk.main()
In nonmodular.Junk.main calling new modX.X()
Exception in thread "main" java.lang.NoClassDefFoundError: modX/X
at nonmodular.Junk.main(Junk.java:5)
at automod/automod.Foo.main(Foo.java:10)
at moduleA/modA.A.main(A.java:10)
Caused by: java.lang.ClassNotFoundException: modX.X
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 3 more
Any idea why? Any class loaded from the classpath should be able to access any classes exported by a module.
When you start a Java application with the --module command, the value you pass is a "root" module. The same is true of modules added via --add-modules. The module system determines the entire module graph from these root modules. In other words, it reads the module-info file, finds the requires directives, and then searches the modulepath for those required modules. It does this transitively. Some modules also declare one or more uses directives on a service. Any modules on the modulepath that provides any of those services will also be loaded, regardless of if any module requires them.
This means if there's a module on the modulepath that isn't required by any loaded module and doesn't provide any services needed by any loaded module then said module won't be loaded. If you're interested in seeing what modules are resolved you can use the following command:
java --show-module-resolution --dry-run -p [MODULEPATH] -m [MODULE]
In your case I can only assume that none of your other modules require modularX, so when its on the modulepath it doesn't get loaded. However, when its on the classpath things work differently and its found by your non-modular code that's also on the classpath. You can still use the modulepath though, just make sure your moduleX module is loaded. This can be forced by using --add-modules:
java -p moduleA.jar;automod.jar;moduleX.jar --add-modules moduleX -cp nonmodular.jar -m moduleA/modA.A
Note you can also limit the modules via --limit-modules.
I'm using v3.7.0 of the plugin as required and JDK 9.0.1. I have added two requires statements, each referring to a jar in the class path (automatic module). The module-info.java compiles successfully in Eclipse after I moved the jars to Modulepath. However, Maven gives me a compiler error saying one of them is missing (strangely, not the first one which is just one line before). I tried to check the automatic module name but I get an error from the commands just for this jar. What does this error mean and how do I fix it so that I can discover the proper module name?
I replaced my username in the output below. The jar in question does use a ServiceLoader but is not compiled with Java 9.
computerName:Commander-java username$ jar --file=/Users/username/.m2/repository/com/username/rcf/1.0/rcf-1.0.jar --describe-module
Unable to derive module descriptor for: /Users/username/.m2/repository/com/username/rcf/1.0/rcf-1.0.jar
Provider class com.username.rcf.server.TestCmdChain not in module
computerName:Commander-java username$ java -p /Users/username/.m2/repository/com/username/rcf/1.0/rcf-1.0.jar --list-modules
Error occurred during initialization of boot layer
java.lang.module.FindException: Unable to derive module descriptor for /Users/username/.m2/repository/com/username/rcf/1.0/rcf-1.0.jar
Caused by: java.lang.module.InvalidModuleDescriptorException: Provider class com.username.rcf.server.TestCmdChain not in module
The answer in How to deal with java keywords in auto generated module names in Java 9? has a different error related to using a Java identifier in the module name. The automatic jar name for my module should just be rcf since the jar name is rcf-1.0.jar. The error I'm getting is different also.
While deriving module description the contents of any
META-INF/services configuration files are mapped to provides
declarations.
The packages scanned for the services are the ones containing class files.
Also, the package name for individual classes is derived from their fully qualified name. From the shared logs com.username.rcf.server shall be the expected package name for the service to be provided and this shall turn into
provides x.y.z.TestCmdChainInterface with com.username.rcf.server.TestCmdChain
Seems like there is no such package com.username.rcf.server existing in your module.
I am fairly new to grails and need help figuring out why I cannot run grails due to this error below:
grails> run-app
| Running application...
startup failed:
C:\DIR\grails-inventory\grails-app\controllers\harbor\AssetController.groovy: 3: unable to resolve class org.apache.jasper.compiler.Node.ParamsAction
# line 3, column 1.
import org.apache.jasper.compiler.Node.ParamsAction;
^
1 error
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':compileGroovy'.
> Compilation failed; see the compiler error output for details.
If I were to comment out that particular line in AssetController, grails will execute however the whole application will have NullPointer errors
Try to add this to Gradle dependencies:
dependencies {
// specify dependencies here under either 'build', 'compile', 'runtime', 'test' or 'provided' scopes e.g.
// runtime 'mysql:mysql-connector-java:5.1.22'
compile 'tomcat:jasper-compiler:5.5.9'
}
You can find jasper for Grails 2.x:https://grails.org/plugin/jasper and plugins for Grails 3.x are here: https://bintray.com/grails/plugins, but as I see there is no Jasper plugin for Grails 3, so try to add dependency directly as mentioned above.