java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter - java-9

After installing JDK9, I get this exception when running my Scala projects. Upgrading Scala to 2.12.2 also didn't resolve my problem.

You can add dependencies in maven
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>

The java.xml.bind module is not resolved by default when running code on the module path. This means that if you depend on JAXB then you need to run with --add-modules java.xml.bind or else deploy JAXB on the class path (or module path).
Update: The "Modules Shared with Java EE Not Resolved by Default" section of JDK 9 Migration Guide provides more information on this topic.

To add to the previous answer I would like to refer to the following answer: https://stackoverflow.com/a/43574427/3751268. I think it covers in details which is the desired way to provide libraries like the jaxb.
In particular for Scala, I add it like this to my libraryDependencies:
libraryDependencies += Seq("javax.xml.bind" % "jaxb-api" % "2.3.0")

Related

Can't resolve maven dependency with beam-runners-google-cloud-dataflow-java and bigtable-client-core

I am trying to run Java code from a Maven project that uses both beam-runners-google-cloud-dataflow-java and bigtable-client-core, and I cannot get it to properly reconcile dependencies amongst these two. When I run and attempt to create a BigtableDataClient, I get the following error:
java.lang.NoSuchFieldError: TE_HEADER
at io.grpc.netty.shaded.io.grpc.netty.Utils.<clinit> (Utils.java:74)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelBuilder.<clinit> (NettyChannelBuilder.java:72)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress (NettyChannelProvider.java:37)
at io.grpc.netty.shaded.io.grpc.netty.NettyChannelProvider.builderForAddress (NettyChannelProvider.java:23)
at io.grpc.ManagedChannelBuilder.forAddress (ManagedChannelBuilder.java:39)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel (InstantiatingGrpcChannelProvider.java:242)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel (InstantiatingGrpcChannelProvider.java:198)
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel (InstantiatingGrpcChannelProvider.java:185)
at com.google.api.gax.rpc.ClientContext.create (ClientContext.java:160)
at com.google.cloud.bigtable.data.v2.stub.EnhancedBigtableStub.create (EnhancedBigtableStub.java:151)
at com.google.cloud.bigtable.data.v2.BigtableDataClient.create (BigtableDataClient.java:138)
at com.google.cloud.bigtable.data.v2.BigtableDataClient.create (BigtableDataClient.java:130)
...
I can only conclude this is due to an issue with version conflict on the relevant libraries (either grpc-netty or grpc-netty-shaded); I'm using 1.17 for grpc-netty and 1.23 for grpc-netty-shaded. I've tried using dependencyManagement to force the use of version 1.23.0 for both grpc-netty and grpc-netty-shaded, and then tried 1.17 for both, but this doesn't help. I've also tried using earlier versions of both the Beam runners and bigtable-client-core, and this doesn't help either.
The relevant Maven dependencies are:
<dependency>
<groupId>org.apache.beam</groupId>
<artifactId>beam-runners-google-cloud-dataflow-java</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-client-core</artifactId>
<version>1.12.1</version>
</dependency>
I look at the code for Utils.java (https://github.com/grpc/grpc-java/blame/master/netty/src/main/java/io/grpc/netty/Utils.java), and I don't see any evidence that I'd be using any earlier version that might not have this constant (it's been there since version 1.7).
I'm completely baffled what the issue is here. How do I identify the dependency conflict? Is there another way I can find what version of the class Maven is actually looking at here?

Spark-submit is not using the protobuf version of my project

In my work project, I use spark-submit to launch my application into a yarn cluster. I am quite new to Maven projects and pom.xml use, but the problem I seem to be having is that hadoop is using an older version of google protobuf (2.5.0) than the internal dependencies I'm importing at work (2.6.1).
The error is here:
java.lang.NoSuchMethodError:
com/google/protobuf/LazyStringList.getUnmodifiableView()Lcom/google/protobuf/LazyStringList;
(loaded from file:/usr/hdp/2.6.4.0-91/spark2/jars/protobuf-java-2.5.0.jar
by sun.misc.Launcher$AppClassLoader#8b6f2bf7)
called from class protobuf.com.mycompany.group.otherproject.api.JobProto$Query
Since I'm not quite sure how to approach dependency issues like this, and I can't change the code of the internal dependency that uses 2.6.1, I added the required protobuf version as a dependency to my project, as well:
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>2.6.1</version>
</dependency>
Unfortunately, this hasn't resolved the issue. When the internal dependency (which does import 2.6.1 on its own) tries to use its proto, the conflict occurs.
Any suggestions on how I could force the usage of the newer, correct version would be greatly appreciated.
Ultimately I found the Maven Shade Plugin to be the answer. I shaded my company's version of protobufs, deployed our service as an uber jar, and the conflict was resolved.

Maven: The type cannot be resolved. It is indirectly referenced from required .class files

I changed some existing projects from ant to maven projects.
So far so good.
All projects do have the same groupId.
Theres a project with name "ServerBase" and artifactId "server-base".
Within this project theres an abstract class "BaseService" which defines a logger via:
import org.jboss.logging.Logger;
[...]
protected Logger log = Logger.getLogger(this.getClass());
Theres another project with name "Server" and artifactId "server".
Within this project theres a class ConfigurationDAOImpl extending the BaseService-Class above.
Within ConfigurationDAOImpl the logger log is used for creating some outputs.
Within the "Server"'s POM file I have declared:
<dependency>
<groupId>com.tcom.amadeus</groupId>
<artifactId>server-base</artifactId>
<version>${project.version}</version>
</dependency>
Under BuildPath the dependency is shown very nice under MavenDependencies. I removed the old dirct/natural/ant-dependency from build path before.
If I remove it I am getting very much errors about missing classes etc.
But although I do have this dependency I am getting the followin error in eclipse (under tab markers):
The type org.apache.commons.logging.Log cannot be resolved. It is indirectly referenced from required .class files
Resource: ConfigurationDAPImpl.java
Path: /Server/src/main/...
Location: Line 24
Type: Java Problem
I tried removing the dependency and add it again but without any luck.
Both projects do refer to JAVA 1.8.
Both projects have been build with targets clean an package multiple times.
Both projects have been updated by Righclick or pressing F5.
I am using Eclipse Version: Neon.1a Release (4.6.1)
I am using apache-maven-3.3.9
I am using m2e Plugin.
Any further help would be grateful.
Thanks in advance.
There are two ways to 'solve' this:
1)
explicitly add the required dependency within the server-projects pom-file:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
2)
change the scop of the required dependency within the server-base-projects pom file from up to now 'provide' to 'compile' or erase the scope tag at all such that the default scope is used by maven (which I guess is 'compile')
old:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope>provided</scope>
</dependency>
new:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
<scope></scope>
</dependency>
or:
<dependency>
<groupId>org.jboss.logging</groupId>
<artifactId>jboss-logging</artifactId>
</dependency>
Some background to this from documentation:
http://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#Transitive_Dependencies
provided This is much like compile, but indicates you expect the JDK or a container to provide the dependency at runtime. For example,
when building a web application for the Java Enterprise Edition, you
would set the dependency on the Servlet API and related Java EE APIs
to scope provided because the web container provides those classes.
This scope is only available on the compilation and test classpath,
and is not transitive.
Thanks all.
It looks like apache logging library is not brought transitively from your server-base project. Check if in project server under MavenDependencies you see commons-logging (apache logging) jar. If not, then add this as your maven dependency in server-base project.
Repeat the above for all jars that server-base depends on.

JavaFX can't load caspian.css

I have a Maven project in which I use a javaxf WebEngine. I first included javafx by installing e(fx)clipse, and I was able to use it normally.
Now I want to compile my program to a big .jar file with all dependencies included. I first used a <scope>system</scope> and linked to the jfxrt.jar in my JDK (1.7.0_45). I compile my program using mvm package and it works well for the build part.
Then, I installed the jfxrt.jar in maven thanks to this SO answer so I have a javafx-2.2.45.jar with maven.
However, I'm stuck with this error when I run my program and when it comes to instantiate that particular WebEngine:
INFO: com.sun.javafx.css.StyleManager loadStylesheetUnPrivileged Could not find stylesheet: jar:file:/target/project-name-0.1.one-jar.jar!/lib/javafx-2.2.45.jar!/com/sun/javafx/scene/control/skin/caspian/caspian.css
SEVERE: javafx.scene.control.Control impl_processCSS The -fx-skin property has not been defined in CSS for ScrollBarThemeImpl$ScrollBarWidget#5919e0a8[styleClass=scroll-bar]
java.lang.NullPointerException
at com.sun.webpane.sg.theme.ScrollBarThemeImpl.initializeThickness(ScrollBarThemeImpl.java:341)
at com.sun.webpane.sg.theme.ScrollBarThemeImpl.access$100(ScrollBarThemeImpl.java:27)
at com.sun.webpane.sg.theme.ScrollBarThemeImpl$ScrollBarWidget.impl_updatePG(ScrollBarThemeImpl.java:50)
at javafx.scene.Node.impl_syncPGNode(Node.java:425)
at javafx.scene.Scene$ScenePulseListener.syncAll(Scene.java:2106)
at javafx.scene.Scene$ScenePulseListener.syncAll(Scene.java:2115)
at javafx.scene.Scene$ScenePulseListener.syncAll(Scene.java:2115)
at javafx.scene.Scene$ScenePulseListener.synchronizeSceneNodes(Scene.java:2082)
at javafx.scene.Scene$ScenePulseListener.pulse(Scene.java:2193)
at com.sun.javafx.tk.Toolkit.firePulse(Toolkit.java:363)
at com.sun.javafx.tk.quantum.QuantumToolkit.pulse(QuantumToolkit.java:463)
at com.sun.javafx.tk.quantum.QuantumToolkit$9.run(QuantumToolkit.java:332)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:76)
I opened this jar and was able to find the caspian.css file where it's supposed to be.
What should I do to be able to use my WebEngine in my "big compiled jar"? I don't care if the solution is a quick, dirty fix such as copy/paste of this css file somewhere else (I already tried that but I might have missed something..)
It's not a good idea to package fx into your jar. Have you tried using http://www.zenjava.com/2013/07/01/javafx-maven-plugin-2-0-released/
You might need to declare your dependency like for not to include JavaFX into the uber jar. You could also exclude javafx packages from when creating this jar, but I don't think it's recommended as in theory resources might not be placed under the javafx package.
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>2.2.3</version>
<scope>provided</scope>
</dependency>
or
<dependency>
<groupId>com.oracle</groupId>
<artifactId>javafx</artifactId>
<version>2.2.3</version>
<optional>true</optional>
</dependency>
Update: the is also a javafx maven plugin as #tomsontom mentioned.

java.lang.ClassNotFoundException: javax.faces.webapp.FacesServlet, tomcat doesn't see javaee-api-7.0-b83.jar

I am trying to run sample guessnumber-jsf from Java EE tutorial. It is here: https://svn.java.net/svn/javaeetutorial~svn
There is no dependencies in pom.xml. So output file has no .jar file. When I try to put javaee-api-7.0-b83.jar inside tomcat/lib or WEB-INF/lib/javaee-api-7.0-b83.jar, nothing changes.
When I try to open
localhost:8080/guessnumber-jsf/faces/greeting.xhtml
I get ClassNotFoundException. Where can I get list of jars that I need for faces tutorial? How can I connect them?
You can't put that Java EE jar in Tomcat and expect it to magically morph into a Java EE server.
That particular jar only contains the APIs to link against (eg "headers" in C/C++ terminology). It does not contain any implementation.
The easiest thing to do is to dish Tomcat and download TomEE instead. Optionally download GlassFish.
These will all already contain all the functionality you need and nothing will have to be put into WEB-INF/lib. (if using Maven put the Java EE 6 GAV as a dependency with scope provided in your pom).
If you are using a Maven project you can fix this error by adding the following dependency:
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.2.7</version>
</dependency>
Adding to the answer of Mike Braun, the Java EE 6 GAV for the web profile is:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6</version>
<scope>provided</scope>
</dependency>
Specifically note the scope: "provided". This means your Maven project will link against this, but it expects your runtime to have the implementations. For TomEE, GlassFish, JBoss AS 7.x, etc this is indeed the case.
In your classpath (.classpath) make sure you have entry like
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>

Resources