Hi,
I see a strange behaviour in Eclipse (2019-03) that I don't know where it
comes from nor how to solve it:
Assume you have the following dependency in your pom.xml:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.8.0-beta4</version>
</dependency>
This Jar contains a module descriptor for Java >= 9 not in the root
folder, i.e. "/", but under META-INF/versions/9.
Add the following entry to your module-info.java:
module myproject {
(...)
requires transitive org.slf4j;
}
Create a Java class containing the following snippet:
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG =
LoggerFactory.getLogger(MyApplication.class);
Compiling the project with Maven on the command line works fine: The
dependency is correctly added to the module path,
When you look in Eclipse into the project properties dialog (Properties ->
Java Build Path -> Libraries), you see that the Jar is listed under
Classpath / Maven Dependencies as being modular ("Is modular - non
modifiable"). Now open the module descriptor and the Java file. What's
happening is:
1) Eclipse complains in the module info editor that it cannot resolve
org.slf4j to a module.
2) In the Java editor the imports are marked as not accessible.
3) The Logger class in the field is underlined and marked as an error
because Logger cannot be resolved to a type. Obviously a subsequent error
of #2.
4) All occurrences of the LOG variable in the Java file are marked as
errors in the Java editor view.
You only see this in the module-info and Java editors when you open them;
there's nothing shown in the problems view or in the package explorer.
As quick fix for the errors at the import statements Eclipse suggests to
add slf4j.api to the module-info.java, i.e. an entry derived from the jars
file name. If you do this, the errors in the Java editor (#2-#4 above)
disappear, but the module-info.java is then marked with an error icon in
the package explorer, and a new error is (correctly) show in the problems
view:
"slf4j.api cannot be resolved to a module"
Funny:
If you comment out the original entry "requires org.slf4j" in the module
descriptor file, then all referenctes to org.slf4j.Logger[Factory] are now
listed as errors in the package explorer and problems view, and
additionally the self-generated entry "requires slf4j.api"...
Erm...
Do you know that's going on here? Is this a bug in m2e? Or Eclipse itself?
Regards
Thorsten
_______________________________________________
m2e-users mailing list
m2e-users@eclipse.org
To change your delivery options, retrieve your password, or unsubscribe from
this list, visit
https://www.eclipse.org/mailman/listinfo/m2e-users