jsonix-schema-compiler
jsonix-schema-compiler copied to clipboard
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
when attempting to run:
java -jar node_modules/jsonix-schema-compiler/lib/jsonix-schema-compiler-full.jar -d mappings -p PO purchaseorder.xsd
on the CLI
I'm trying to get the examples working before I try real data. Any help would be greatly appreciated.
This should be part of JRE. Which Java version do you use?
I updated to java version "9" Java(TM) SE Runtime Environment (build 9+181) Java HotSpot(TM) 64-Bit Server VM (build 9+181, mixed mode)
and i'm now getting the following error:
Exception in thread "main" java.lang.Error: java.lang.reflect.InvocationTargetException
at com.sun.tools.xjc.reader.Ring.get(Ring.java:113)
at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.
Java 8 should work.
With Java 9 it's probably the new module system which does not load javax.activation
. I don't have Java 9 experience yet so not sure how to fix this.
I just ran into the same issue. From java 9 on, jaxb (and some other JEE modules are not provided on the default classpath anymore. --add-modules java.xml.bind
should do the trick.
java --add-modules java.xml.bind -jar node_modules/jsonix/lib/jsonix-schema-compiler-full.jar -d mappings -p PO purchaseorder.xsd
I tried adding --add-modules java.xml.bind
like @henkesn directed but now I'm hit with this:
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/Users/ghdna/jsonix-schema-compiler-full-2.3.9.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
P.S. The conversion still went through.
@ghdna thank you so much , that's was helpfull for me . it work (y)
I tried running an Arabic tokenizer/diacritizer and got the same error message:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583) ...
I have limited experience in Java. As instructed by the developer, I entered the following line via the terminal: java -Xmx2500m -Xms2500m -XX:NewRatio=3 -jar MADAMIRA-release-20170403-2.1.jar -rawinput samples/raw/SampleTextInput.txt -rawoutdir . -rawconfig samples/sampleConfigFile.xml
Can anyone let what could be the cause of this error and how to fix it?
@fhr21 try to add --add-modules java.xml.bind
as first argument.
The developer wrote this command to run the program thru the terminal in mac computer:
java -Xmx2500m -Xms2500m -XX:NewRatio=3 -jar MADAMIRA-release-20170403-2.1.jar -rawinput samples/raw/inputdata.txt -rawoutdir samples/rawoutputdata.txt -rawconfig samples/sampleConfigFile.xml
I tried running the program replacing the first argument with with the line you gave me as follows:
java --add-modules java.xml.bind -jar MADAMIRA-release-20170403-2.1.jar -rawinput samples/raw/inputdata.txt -rawoutdir samples/rawoutputdata.txt -rawconfig samples/sampleConfigFile.xml
This is what I get:
Error occurred during initialization of boot layer java.lang.module.FindException: Module java.xml.bind not found
Error occurred during initialization of boot layer java.lang.module.FindException: Module java.xml.bind not found
As of https://stackoverflow.com/questions/52502189/java-11-package-javax-xml-bind-does-not-exist, it was removed in Java11. Adding following lines to Maven's pom.xml helped me:
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-core</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
I was having this problem with Java 8, spring boot and camel, this solution worked for me.
I am having the same issue and also tried the --add-modules java.xml.bind but getting this: Error occurred during initialization of boot layer java.lang.module.FindException: Module java.xml.bind not found
And I am using jdk 11.0.8
As noted in the following post, java.xml.bind has been removed from Java 11+. https://stackoverflow.com/a/52502208
However, with a side-by-side installation of a lower version (Java 10 in my case), I was able to make the following command work in Windows via powershell:
."C:\Program Files\Java\jdk-10.0.2\bin\java.exe" --add-modules java.xml.bind -jar ".\jsonix-schema-compiler-full-2.3.9.jar" -generateJsonSchema .\schemas\order.xsd
changing version java to 8 will help
I was able to download activation.jar and use this:
java -cp jsonix-schema-compiler-full.jar:./activation.jar org.hisrc.jsonix.JsonixMain -generateJsonSchema ...
This actually related to java version, this work only under java 8, see JAVA8_HOME
So to fix this, I used java 8 docker image.
docker run --rm -v "$PWD":/jsonix/ -w /jsonix adoptopenjdk/openjdk8:jre8u282-b08 java -jar jsonix/jsonix-schema-compiler-full-2.3.9.jar -d mappings -p PO jsonix/**/**.xsd
This is temporary, I propose migrate java version, https://stackoverflow.com/questions/52502189/java-11-package-javax-xml-bind-does-not-exist
I was able to download activation.jar and use this:
java -cp jsonix-schema-compiler-full.jar:./activation.jar org.hisrc.jsonix.JsonixMain -generateJsonSchema ...
That is not necessary, see https://github.com/highsource/jsonix-schema-compiler/issues/81#issuecomment-1232816294
I am trying to build the tool from source, but since, there are too many changes it seems the build itself is quite broken. Any plans to add support for JAVA8+?