jsonix-schema-compiler icon indicating copy to clipboard operation
jsonix-schema-compiler copied to clipboard

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource

Open robgwheeler opened this issue 6 years ago • 18 comments

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.

robgwheeler avatar Mar 18 '18 16:03 robgwheeler

This should be part of JRE. Which Java version do you use?

highsource avatar Mar 19 '18 17:03 highsource

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.(BGMBuilder.java:147) at com.sun.tools.xjc.reader.xmlschema.BGMBuilder.build(BGMBuilder.java:117) at com.sun.tools.xjc.ModelLoader.annotateXMLSchema(ModelLoader.java:425) at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:174) at com.sun.tools.xjc.ModelLoader.load(ModelLoader.java:119) at org.hisrc.jsonix.JsonixMain.execute(JsonixMain.java:99) at org.hisrc.jsonix.JsonixMain.main(JsonixMain.java:77)

robgwheeler avatar Mar 19 '18 18:03 robgwheeler

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.

highsource avatar Mar 19 '18 20:03 highsource

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

henkesn avatar Apr 27 '18 12:04 henkesn

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 avatar Jul 17 '18 16:07 ghdna

@ghdna thank you so much , that's was helpfull for me . it work (y)

AsmaZbt avatar Aug 31 '18 14:08 AsmaZbt

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.(RuntimeBuiltinLeafInfoImpl.java:461) at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.(RuntimeTypeInfoSetImpl.java:65) ....

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 avatar Dec 13 '18 04:12 fhr21

@fhr21 try to add --add-modules java.xml.bind as first argument.

henkesn avatar Dec 13 '18 07:12 henkesn

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

fhr21 avatar Dec 13 '18 19:12 fhr21

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>

meow-sokovykh avatar Dec 27 '18 02:12 meow-sokovykh

I was having this problem with Java 8, spring boot and camel, this solution worked for me.

atvamshi avatar Apr 16 '19 15:04 atvamshi

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

dipak-ksolves avatar Sep 08 '20 12:09 dipak-ksolves

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

poebrand avatar May 25 '21 01:05 poebrand

changing version java to 8 will help

iamsr avatar Jul 06 '21 06:07 iamsr

I was able to download activation.jar and use this:

java -cp jsonix-schema-compiler-full.jar:./activation.jar org.hisrc.jsonix.JsonixMain -generateJsonSchema ...

tmm1 avatar Apr 22 '22 22:04 tmm1

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

romdhanisam avatar Aug 31 '22 11:08 romdhanisam

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

romdhanisam avatar Aug 31 '22 11:08 romdhanisam

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+?

AmeyaVS avatar Feb 17 '24 11:02 AmeyaVS