Eclipse Java 11 classpath only not working compared to Maven - eclipse

Migrating an old ERP system to JPMS turned out to be highly problematic (Java 11 Eclipse finds automatic module, Maven does not), so I decided to first try and simply replace Java 8 with Java 11, but keep everything on the classpath by not introducing any module-info.java files. That actually went quite smoothly; Maven is compiling this without problems, and the resulting application also starts from the command line.
But when I import that Maven project into Eclipse 2019-03 it complains about a.o. java.xml packages, for example this import:
import javax.xml.namespace.QName;
This makes sense, because the JRE is modularized, and those classes are in the java.xml module which I am not included. But why is Maven then compiling correctly AND the application starting under J11?
I suspect I need to tell Eclipse to "--add-modules=ALL-SYSTEM" for this project, but I'm not sure where or how. I've tried moving all the JDK/JRE modules in the build-path/libraries from implicit to explicit, but that does not help.

You probably have some redundant xml api jars on the classpath and javac (incorrectly) doesn't complain because of JDK-8215739, but Eclipse already (correctly) does after bug 536928
At runtime, the JVM seems to ignore packages on the classpath that already appear in a named module, so javac's behaviour is actually consistent with that.
To fix your problem: Try "Open Type" to find any copies of javax.xml.namespace.QName in jars on your classpath and exclude those dependencies in your pom.xml

"Try "Open Type" to find any copies of javax.xml.namespace.QName in jars on your classpath and exclude those dependencies in your pom.xml"
This was also the solution for my problem.In my case, I had to exclude "org.apache.axis" from axis and add a separated dependency for javax.xml.rpc
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
<exclusions>
<exclusion>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
</exclusion>
<exclusion>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.xml.rpc</groupId>
<artifactId>javax.xml.rpc-api</artifactId>
<version>1.1.2</version>
</dependency>

for any poor souls still working with axis 1.3, the group id you need to exclude is just axis
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.3</version>
<exclusions>
<exclusion>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
</exclusion>
<exclusion>
<groupId>axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
</exclusion>
</exclusions>
</dependency>

Related

JDK 11 with JAXB and JAXWS works with Eclipse but not IntelliJ

I am converting an application that uses JAXB and JAX-WS from JDK 8 to JDK 11. The code runs when I use Eclipse IDE but exactly the same code fails with IntelliJ IDEA
I have created a Maven project using both Eclipse and IntelliJ IDEA. The problems of finding a working combination of Maven resources has been described in another question. JDK 11 with JAXB and JAXWS problems
The code builds without error in both environments. I have tried creating the IntelliJ IDEA project as a Maven project as well as a standard IDEA project
part of pom.xl
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11.0.2</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.0</version>
</dependency>
<!-- JAXWS for Java 11 -->
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>rt</artifactId>
<version>2.3.1</version>
</dependency>
module-info.java
module org.openfx.gustfx {
requires javafx.controls;
requires javafx.fxml;
requires transitive javafx.graphics;
requires java.xml.bind;
requires java.xml.ws;
requires javax.jws;
opens com.agile.ws.schema.common.v1.jaxws to javafx.fxml;
opens org.openfx.gustfx to javafx.fxml;
exports org.openfx.gustfx;
}
When the code is run from Eclipse, there are no errors.
Running the same code from IntelliJ IDE results in this error
java.lang.ClassNotFoundException: com.sun.xml.internal.ws.spi.ProviderImpl
Searching through the jar files confirms that ProviderImpl.class is now located in com.sun.ws.spi not in com.sun.xml.internal.ws.spi This does not cause a problem with eclipse but IDEA reports the ClassNotFoundException
Therefore, my question "How does eclipse resolve this problem while IntelliJ does not ?"
With help from Roman Shevchenko at IntelliJ, I have solved this problem using the following pom.xml
<dependency>
<groupId>com.sun.xml.ws</groupId>
<artifactId>jaxws-rt</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>javax.jws</groupId>
<artifactId>javax.jws-api</artifactId>
<version>1.1</version>
</dependency>
and module-info.java
requires java.xml.ws;
requires java.xml.bind;
requires javax.jws;

Maven eclipse plugin, exclude transitive dependencies

There are several questions about maven and transitive dependency exclusion. However, I don't get it working. I have some dependencies in my pom, that repackaged some libraries, in order to reduce the size of the pom. So far this is successful. But when I'm running mvn eclipse:eclipse these transitive dependencies get written into the .classpath file. Even though they are excluded like in the following excerpt.
<dependency>
<groupId>foo.bar</groupId>
<artifactId>foobar</artifactId>
<version>1.2.4</version>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T13:57:37+02:00)
Java version: 1.7.0_45, vendor: Oracle Corporation
I have found that the m2eclipse plugin for Eclipse provides better integration than maven-eclipse-plugin does. Apache itself has stopped maintaining it and advises going for m2eclipse instead.
Try in Eclipse to "import as Maven Project".

strange thing about eclipse and maven, and eclipse's auto build

I use STS and it's a spring web project.
when i run maven build manually, shows:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
but this project still can auto build and deploy to tomcat
so Does the eclipse use maven to build my project when i save file and use auto build
First of all. Regarding the dependencies.
I am covering this aspect in case you have forgoten to add the required dependecy.
In order to add SLF4J you must put ONE and only ONE of these dependencies in your pom.xml. It depends on what implementation you choose to use. Every dependency you add in the pom.xml is added automatically in the classpath. If one of the below dependencies are provided by another dependency then you can omit it. Dont forget that you must include only one even if the dependency is provided by another dependency. Notice that i have omitted the version from the dependencies. Use the latest available.
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version></version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version></version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version></version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version></version>
<scope>compile</scope>
</dependency>
Regarding the annoying error
If after having only one of the above dependencies you still get the SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". then you are facing a bug from m2e.
Eclipse Juno and Indigo, when using the bundled maven version(m2e), are not suppressing the message SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". This behaviour is present from the m2e version 1.1.0.20120530-0009 and onwards.
Although, this is indicated as an error your logs will be saved normally. The highlighted error will still be present until there is a fix of this bug. More about this in the m2e support site.
The current available solution is to use an external maven version rather than the bundled version of Eclipse. You can find about this solution and more details regarding this bug in the question below which i think describes the same problem you are facing.
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". error
You need to make sure at least on binding implementation of slf4j is in your classpath, i.e:
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
</dependency>
You need to add the dependency of implementation of slf4j to you pom.xml , such as slf4j-nop.

How can I see which POm dependency entry is adding a certain jar to eclipse classpath

Is it possible using the m2e maven plugin for eclipse (or some other easy way), to figure out which <dependency> entry in my POM is the reason for a given .jar to be added to the classpath. afaik right click only allows me to see the pom of the given artifact.
in this example the my pom looks like
<dependencies>
<dependency>
<groupId>eu.medsea.mimeutil</groupId>
<artifactId>mime-util</artifactId>
<version>2.1.1</version>
</dependency>
</dependencies>
so it's pretty easy to understand that who is responsible for adding the log4j things
Open the POM in the m2e POM editor (should happen by default), click Dependency Hierarchy, type the name of the offending dependency into the filter box. It will highlight the dependency that drags it in.
Oh well figured it ..
right click->maven->exclude maven artifact would place a nice exclusion element on the dependency causing the inclusion
<dependencies>
<dependency>
<groupId>eu.medsea.mimeutil</groupId>
<artifactId>mime-util</artifactId>
<version>2.1.1</version>
<exclusions>
<exclusion>
<artifactId>slf4j-api</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

Maven missing transitive dependency

I have a maven project with a dependency (datanucleus-db4o). This dependency has itself a dependency on db4o (db4o:db4o:jar:7.12.126.14142-all-java5).
Now maven says:
09.09.10 19:43:09 MESZ: Missing artifact db4o:db4o:jar:7.12.126.14142-all-java5:compile
I am new to maven. Is it right that datanucleus-db4o defines its own dependency with a specific version number? Is this a good way? m2eclipse can't download it. I downloaded a newer Version of db4o and added it to the classpath. Maven keeps writing about the missing artifact.
Also I've got NoClassDefFound errors when I launch my application. This leads me to the other question:
Am I doing something wrong?
Thanks in advance.
Here is the relevant part of the pom.xml...
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-core</artifactId>
<version>2.2.0-m1</version>
<type>jar</type>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-db4o</artifactId>
<version>2.1.1</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
and here is the relevant part of the pom.xml of
<dependency>
<groupId>db4o</groupId>
<artifactId>db4o</artifactId>
<version>7.12.126.14142-all-java5</version>
</dependency>
Is it right that datanucleus-db4o defines its own dependency with a specific version number? Is this a good way?
I'm not sure I understood the question... Anyway, there is indeed something wrong with the db4o:db4o dependency of the datanucleus-db4o artifact: it is not available in Maven central nor in the DataNucleus repository. I don't understand how users are supposed to use the datanucleus-db4o artifact.
I downloaded a newer Version of db4o and added it to the classpath. Maven keeps writing about the missing artifact.
Not sure what you did exactly but maybe the following will work: exclude the dependency that can't be resolved and replace it with some equivalent from the db4o repository.
<dependencies>
...
<dependency>
<groupId>org.datanucleus</groupId>
<artifactId>datanucleus-db4o</artifactId>
<version>2.1.1</version>
<type>jar</type>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>db4o</groupId>
<artifactId>db4o</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.db4o</groupId>
<artifactId>db4o-full-java5</artifactId>
<version>7.12-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
...
<repository>
<id>db4o</id>
<url>https://source.db4o.com/maven</url>
</repository>
</repositories>
I have no idea if this will work of course.
Also I've got NoClassDefFound errors when I launch my application. This leads me to the other question:
Can't say since you didn't post the error. But give the above a try.
The required file is not in the maven repositories, but it is in the datanucleus zip file (that one with all dependencies). Look into the /deps folder.
I unpacked it and installed it into the local maven repository with this command:
./mvn install:install-file -Dfile=/home/myUser/Downloads/db4o-7.12.126.14142-all-java5.jar -DgroupId=db4o -DartifactId=db4o -Dversion=7.12.126.14142-all-java5 -Dpackaging=jar
After that it is found by maven. Now there are other problems going on. I'll try to solve them myself...
Seems like the JDO or Datanucleus stuff is not well organized at the moment. I think they refactored some classes and now they can't be found at some versions and implementations are incompatible with the api and such stuff.