Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
robgwheeler opened this issue Mar 18, 2018 · 18 comments

Comments

@robgwheeler
Copy link

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.

@highsource
Copy link
Owner

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

@robgwheeler
Copy link
Author

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)

@highsource
Copy link
Owner

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.

@henkesn
Copy link

henkesn commented Apr 27, 2018

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

@ghdna
Copy link

ghdna commented Jul 17, 2018

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.

@AsmaZbt
Copy link

AsmaZbt commented Aug 31, 2018

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

@fhr21
Copy link

fhr21 commented Dec 13, 2018

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?

@henkesn
Copy link

henkesn commented Dec 13, 2018

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

@fhr21
Copy link

fhr21 commented Dec 13, 2018

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

@meow-sokovykh
Copy link

meow-sokovykh commented Dec 27, 2018

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>

@atvamshi
Copy link

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

@dipak-ksolves
Copy link

dipak-ksolves commented Sep 8, 2020

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

@poebrand
Copy link

poebrand commented May 25, 2021

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

@iamsr
Copy link

iamsr commented Jul 6, 2021

changing version java to 8 will help

@tmm1
Copy link

tmm1 commented Apr 22, 2022

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

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

@romdhanisam
Copy link

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
Copy link

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 #81 (comment)

@AmeyaVS
Copy link

AmeyaVS commented Feb 17, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests