JDK 10 cannot import javax.xml.namespace in Eclipse - java

It's very strange. I am moving a dynamic web project from Java 8 to Java 10.
The last thing I cannot get the dependency resolved is the javax.xml.namespace.QName class.
You can see in the attached screen shot, the QName class exist in JRE System Library, but the IDE keep complaining that QName cannot be resolved to a type.

There probably is a duplicate dependency pulled in from some other dependency.
In eclipse do
"Navivate -> Open Type..."
Type in "java.xml.namespace".
If there are other results than from your (Open-)JDK, these need to be removed in the following steps. In my case it was xml-apis
Open your pom.xml in eclipse, and visit the "Dependency Hierarchy" tab to check which dependency was pulling in xml-apis
Type "xml-apis" in the Filter. In my case the top level dependency that was pulling xml-apis was "esapi"
exclude xml-apis from the esapi dependency:
<dependency>
<groupId>org.owasp.esapi</groupId>
<artifactId>esapi</artifactId>
<version>2.2.0.0</version>
<exclusions>
<exclusion>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
</exclusion>
</exclusions>
</dependency>
Right click your Project and choose "Maven -> Update Project...". Check your project and click OK.
That's it

I had the same error moving from Java 8 to Java 11,
and I included an explicit dependency on the library stax-api 1.0-2:
<dependency>
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
<version>1.0-2</version>
</dependency>
and excluded any transitional dependency on the library stax-api 1.0.1:
...
<exclusion>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
...
After this, my IDE found the lost import javax.xml.namespace.QName correctly.
I hope this helps.

Try to change the order of elements on your classpath. The JRE must be before the Maven Dependencies. That fixes the issue.
My guess is that the Java 10 compiler notices that you're trying to replace internal classes (java.xml.namespace) with code from JARs and it doesn't like that.

Resolved it by removing jsr173_api.jar from the project classpath (project -> properties -> java build path -> libraries -> classpath). It appears again when eclipse project rebuilt.

This worked! Checking for multipletypes Ctrl+Shift+T, removing unwanted ones.

I have had the same experience with the JRE 11, and Gradle 7.5. If it helps anyone, you can exclude xml-apis as such:
configurations {
all {
exclude group: 'xml-apis', module: 'xml-apis'
}
}

Related

How to solve dependency problem in maven because of using different versions of same project

I have 4 modules in my project.
Module1 (i.e. com.assign.print:printlog.value:3.0.0-SNAPSHOT) has one class i.e. Foo.java, inside this class, on more class is there which is using com.print.assess: mns.pro:2.0
Module2 , Module2 and Module4 are using com.print.assess: mns.pro:6.2.
In my project main pom.xml, the dependency is added as :
<dependency>
<groupId>com.print.assess</groupId>
<artifactId>mns.pro</artifaxtId>
<version>6.2</version>
</dependency>
In Foo.java, I have one class as DataVal.java which is using older version.
If I don't add
<dependency>
<groupId>com.print.assess</groupId>
<artifactId>mns.pro</artifaxtId>
<version>2.0</version>
</dependency>
to Module1 pom.xml, Redline error is coming for DataVal.java saying "cannot resolve the symbol". So when I added the dependency with version 2.0, the error was resolved but while installing project:
Failed while enforcing releasability the error(s) are [
Dependency convergence error for com.print.assess:mns.pro:6.2 paths to
dependency are:
+-com.assign.print:printlog.value:3.0.0-SNAPSHOT
+-com.app.print:print.sal:1.1.3
+-com.print.assess:mns.pro:6.2
and
+-com.assign.print:printlog.value:3.0.0-SNAPSHOT
+-com.print.assess:mns.pro:2.0
and
+-com.assign.print:printlog.value:3.0.0-SNAPSHOT
+-com.print.assess.over:multi-task.rev:3.1
+-com.print.assess:mns.pro:6.2
How to resolve this issue?
Thanks in advance
If you have the dependencyConvergence enforcer rule active (which you obviously have), you need to determine your versions in the <dependencyManagement> (which is different from the standard <dependencies>).
Then you can declare the dependencies without version in <dependencies>. dependencyManagement entries can be in the main pom and in modules as well. #Bahmut gave you the link to understand dependencyManagement.
You may want to move your 6.2 dependency in your main pom to <dependencyManagement> so it does not get imported by default. Then you can simply import the 6.2 version in your module poms like this:
<dependency>
<groupId>com.print.assess</groupId>
<artifactId>mns.pro</artifaxtId>
</dependency>
and in the module where you need version 2, you can import it like this:
<dependency>
<groupId>com.print.assess</groupId>
<artifactId>mns.pro</artifaxtId>
<version>2.0</version>
</dependency>
More information about dependency management can be found here:
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

Maven dependency weird bug

I have 4 projects in my eclipse workspace. They are all 4 maven projects. The names are API, Games, Faction, Board.
API is used in all the other maven projects (Games, Faction, Board) and itself depends of a jar into my PC and also HikariCP.
I declare this dependencies in my API pom.xml
<dependency>
<groupId>org.github.paperspigot</groupId>
<artifactId>paperspigot-api</artifactId>
<version>1.7.10-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}\lib\paperspigot-1.7.10-R0.1-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.8</version>
<scope>compile</scope>
</dependency>
Then I declare on my 3 other projects that they depend of API
<dependency>
<groupId>net.onima</groupId>
<artifactId>onimaapi</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
But I have a big warning on the API and the error log says this:
I don't understand why is there this error as I can code with the API in my classes. Can someone explain me? Thanks
EDIT: As requested the text of the screenshot:
Description Resource Path Location Type
Project 'OnimaAPI' is missing required Java project: 'paperspigot' OnimaAPI Build path Build Path Problem
Description Resource Path Location Type
Project 'OnimaGames' is missing required Java project: 'onimaapi' OnimaGames Build path Build Path Problem
I don't know why I can't set the pom.xml here so here's a link: https://ghostbin.com/paste/r4u62
You're declaring paperspigot with system scope.
<dependency>
<groupId>org.github.paperspigot</groupId>
<artifactId>paperspigot-api</artifactId>
<version>1.7.10-R0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}\lib\paperspigot-1.7.10-R0.1-SNAPSHOT.jar</systemPath>
</dependency>
Dependencies with the scope system are always available and are not looked up in repository. They are usually used to tell Maven about dependencies which are provided by the JDK or the VM.
https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#System_Dependencies
You should declare it with compile scope:
This is the default scope, used if none is specified. Compile dependencies are available in all classpaths of a project. Furthermore, those dependencies are propagated to dependent projects.

Not able to use #Inject in eclipse 4

I am trying to use dependency injection in my eclipse project. I included maven dependency for org.eclipse.e4.core.di in my dependency management pom.
<dependency>
<groupId>org.eclipse.e4</groupId>
<artifactId>org.eclipse.e4.core.di</artifactId>
<version>1.5.0-SDK-4.5.0</version>
</dependency>
And also, in the plugin where I am using dependency injection with compile scope.
<dependency>
<groupId>org.eclipse.e4</groupId>
<artifactId>org.eclipse.e4.core.di</artifactId>
<version>compile</version>
</dependency>
After this, when I try to use the annotation #Inject, I am seeing error and I am not able to see any import suggestion also.
I have tried including the following in the pom also
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.2</version>
</dependency>
What is causing this problem? I am using Java 8.
To use #Inject you must include javax.inject in the Require-Bundle or Import-Package entries in the MANIFEST.MF of your plug-in.
To do this in the MANIFEST.MF editor go to the Dependencies tab and add javax.inject to the Required Plug-ins or Imported Packages section.
When you have done this you should be able to use
import javax.inject.Inject;
in your code.
Note: Only classes created from entries in the e4 Application.e4xmi are injected unless you use ContextInjectionFactory to create the class.

maven dependency + local jar in build path = slf4j conflict

I try to use the IMPINJ Octane SDK Java which comes as a jar including all needed dependencies together with Spark Framework in a maven project. To include the Spark Framework I use maven and the Octane SDK jar is added to the build path. My pom.xml has only the spark dependency:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
</dependency>
Every time I try to run the program I get to following error.
Exception in thread "Thread-1" java.lang.NoSuchMethodError: org.slf4j.helpers.MessageFormatter.arrayFormat(Ljava/lang/String;[Ljava/lang/Object;)Lorg/slf4j/helpers/FormattingTuple;
at org.eclipse.jetty.util.log.JettyAwareLogger.log(JettyAwareLogger.java:619)
at org.eclipse.jetty.util.log.JettyAwareLogger.info(JettyAwareLogger.java:314)
at org.eclipse.jetty.util.log.Slf4jLog.info(Slf4jLog.java:74)
at org.eclipse.jetty.util.log.Log.initialized(Log.java:186)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:298)
at org.eclipse.jetty.util.log.Log.getLogger(Log.java:288)
at org.eclipse.jetty.util.component.AbstractLifeCycle.<clinit>(AbstractLifeCycle.java:35)
at spark.embeddedserver.jetty.EmbeddedJettyFactory.create(EmbeddedJettyFactory.java:34)
at spark.embeddedserver.EmbeddedServers.create(EmbeddedServers.java:57)
at spark.Service.lambda$init$0(Service.java:342)
at java.lang.Thread.run(Thread.java:745)
The Octane SDK comes with slf4j and the Spark Framework also has slf4j as a dependency but they have different versions. I found the following thread NoSuchMethodError with SLF4J API but since I could remove slf4j from the jar I can't resolve the problem. How can I get this working?
I also tried to exclude slf4j in the pom but it did not work either:
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
</exclusion>
</exclusions>
</dependency>
EDIT (SOLUTION):
I extracted the Octane SDK jar, removed slf4j and compressed it back to a jar.
My understanding is that sparks requires slf4j 1.7.13.
Then, you add Octane to the classpath (not through a maven dependency) and this Octane jar contains older classes of slf4j.
I just downloaded Octane to see for myself. I notice it include 2 versions:
OctaneSDKJava-1.22.0.30.jar
OctaneSDKJava-1.22.0.30-jar-with-dependencies.jar
You need to use OctaneSDKJava-1.22.0.30.jar and manually include all other dependencies but NOT the slf4j one (or the opposite, use OctaneSDKJava-1.22.0.30-jar-with-dependencies.jar and remove slf4j).
EDIT to answer a question in the comments:
I opened the latest OctaneSDKJava-1.26.2.0-jar-with-dependencies.zip, which contains a README.txt with the following details:
DEPENDENCIES
RUNTIME DEPENDENCIES
jdom 1.0 http://www.jdom.org
log4j 1.2.15 http://logging.apache.org/log4j/1.2/download.html
jargs 1.0 http://sourceforge.net/project/showfiles.php?group_id=33024
mina 1.1.7 http://mina.apache.org
slf4j-log4j12 1.5.0 http://www.slf4j.org
slf4j-api 1.5.0 http://www.slf4j.org
xerces-j 2.4.0 http://xerces.apache.org/
COMPILE DEPENDENCIES
velocity-dep 1.5 http://velocity.apache.org
jalopy 0.3.1 http://jalopy.sourceforge.net
jdom 1.0 http://www.jdom.org
log4j 1.2.15 http://logging.apache.org/log4j/1.2/download.html
commons-collection 3.2 http://commons.apache.org
commons-configuration 1.5 http://commons.apache.org
commons-lang 2.3 http://commons.apache.org
common-logging 1.1.1 http://commons.apache.org
JAXB RI dependencies including:
jaxb-xjc 2.0 https://jaxb.dev.java.net/
jaxb-impl 2.0 https://jaxb.dev.java.net/
jaxb-api 2.0 https://jaxb.dev.java.net/
activation 2.0 https://jaxb.dev.java.net/
jsr173_1.0_api 2.0 https://jaxb.dev.java.net/
The five above jaxb dependencies are available in a single jar "JAXB
RI" from https://jaxb.dev.java.net/. Execute this jar (doubleclick
windows, "java -jar " all other platforms) and copy the
individual jars to the LTKJava/lib directory) plus above runtime
dependencies
TEST DEPENDENCIES
JUnit 4.4 http://sourceforge.net/project/showfiles.php?group_id=15278
plus above dependencies note that the junit dependency needs to be
placed in the ANT_HOME/lib directory

Android: error including/repacking dependencies which reference javax core classes

I'm working on an Android app using Maven as the build tool. I managed to set evertyhing up correctly (maven dependencies are exported to the apk etc.), however I have one remaining problem which is driving me crazy.
I want to include a dependency on simpleframework's xml parser defined as follows in my POM file:
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.5.3</version>
</dependency>
When I issue mvn install on the project, I get the following error (truncated):
trouble processing "javax/xml/namespace/NameSpaceContext.class" ...
I know the error results from the simple xml parser referencing these javax-classes, however I haven't found a solution yet (setting the --core-library flag is of no use).
I'm currently trying to repack the dependency with the maven-jarjar-pluging but this doesn't seem to work either.
Can anyone help me out with this? Many, many thanks in advance!
Define your simple-xml depedency like this :
<dependency>
<groupId>org.simpleframework</groupId>
<artifactId>simple-xml</artifactId>
<version>2.6.1</version>
<exclusions>
<!-- StAX is not available on Android -->
<exclusion>
<artifactId>stax</artifactId>
<groupId>stax</groupId>
</exclusion>
<exclusion>
<artifactId>stax-api</artifactId>
<groupId>stax</groupId>
</exclusion>
<!-- Provided by Android -->
<exclusion>
<artifactId>xpp3</artifactId>
<groupId>xpp3</groupId>
</exclusion>
</exclusions>
</dependency>
I use android-maven-plugin, and adding <coreLibrary>true</coreLibrary> to the <configuration> tag of the plugin in the POM works for me. However, there's a bug: https://github.com/jayway/maven-android-plugin/pull/34, that you need to include to fix the plugin you are using, since the bug won't be fixed until 3.0. Here's how I got it working for me using 2.9.0-SNAPSHOT.
add a pluginRepository pointing to http:// oss.sonatype.org/content/repositories/jayway-snapshots/ to get 2.9.0-SNAPSHOT
update your plugin version to use 2.9.0-SNAPSHOT and add <coreLibrary>true</coreLibrary> to pom.xml
get the fix: git clone https://github.com/kevinpotgieter/maven-android-plugin.git
remove src/test/java/com: so the test won't fail
mvn package
copy it and overwrite your local maven cache in .m2 (You may need to remove your plugin repository yours gets overwritten every time.)
Step 3-6 won't be necessary after the fix gets into 2.9.0-SNAPSHOT.
Update July 2010: 2.9.0-beta-4 has the fix, so you don't need the above workaround if you use 2.9.0-beta-4 or later. I tested 2.9.0-beta-5 which worked just fine.
Spring Android uses Maven to integrate Simple. Take a look at the following URL, it should provide pointers on how to get Maven working with Simple.
http://static.springsource.org/spring-android/docs/1.0.x/reference/html/rest-template.html

Categories

Resources