23

i'm trying to generate class stubs for a wsdl with Intellij-Idea 2017.2.5 (Webservices -> Generate code from wsdl...) using JDK-9

I'm getting this exception and i wonder how to tell intellij to pass "--add-modules java.activation" to complete the operation.

(i guess i should run wsimport from the command line...)

Exception in thread "main" java.lang.NoClassDefFoundError: javax/activation/DataSource
    at com.sun.xml.bind.v2.model.impl.RuntimeBuiltinLeafInfoImpl.<clinit>(RuntimeBuiltinLeafInfoImpl.java:461)
    at com.sun.xml.bind.v2.model.impl.RuntimeTypeInfoSetImpl.<init>(RuntimeTypeInfoSetImpl.java:65)
    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:133)
    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.createTypeInfoSet(RuntimeModelBuilder.java:85)
    at com.sun.xml.bind.v2.model.impl.ModelBuilder.<init>(ModelBuilder.java:156)
    at com.sun.xml.bind.v2.model.impl.RuntimeModelBuilder.<init>(RuntimeModelBuilder.java:93)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getTypeInfoSet(JAXBContextImpl.java:455)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:303)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl.<init>(JAXBContextImpl.java:142)
    at com.sun.xml.bind.v2.runtime.JAXBContextImpl$JAXBContextBuilder.build(JAXBContextImpl.java:1174)
    at com.sun.tools.xjc.reader.xmlschema.bindinfo.BindInfo.getJAXBContext(BindInfo.java:335)
    at com.sun.tools.xjc.reader.internalizer.SCDBasedBindingSet.apply(SCDBasedBindingSet.java:235)
    at com.sun.tools.xjc.ModelLoader.createXSOM(ModelLoader.java:541)
    at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:269)
    at com.sun.tools.xjc.api.impl.s2j.SchemaCompilerImpl.bind(SchemaCompilerImpl.java:95)
    at com.sun.tools.ws.processor.modeler.wsdl.JAXBModelBuilder.bind(JAXBModelBuilder.java:142)
    at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildJAXBModel(WSDLModeler.java:2244)
    at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.internalBuildModel(WSDLModeler.java:191)
    at com.sun.tools.ws.processor.modeler.wsdl.WSDLModeler.buildModel(WSDLModeler.java:137)
    at com.sun.tools.ws.wscompile.WsimportTool.buildWsdlModel(WsimportTool.java:391)
    at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:204)
    at com.sun.tools.ws.wscompile.WsimportTool.run(WsimportTool.java:179)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at com.sun.tools.ws.Invoker.invoke(Invoker.java:135)
    at com.sun.tools.ws.WsImport.main(WsImport.java:57)
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource
    at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
    at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    ... 28 more
George
  • 354
  • 1
  • 3
  • 8

4 Answers4

43

Based on your error message, you need to add the following dependency in your pom.xml

<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>1.1.1</version>
</dependency>

From SDK 9, for JAXB to work for web services you need to also have the following dependencies if you do not already have them as they are not part of the SDK.

<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>
Sameer Khanal
  • 1,199
  • 12
  • 11
  • 1
    For gradle builds, add `compile('javax.activation:activation:1.1')` (check the correct version on [maven central](http://mvnrepository.com/artifact/javax.activation/activation)). – miha Jun 05 '18 at 13:59
  • Thanks,I added `/tomcat/lib/javax.activation-1.2.0.jar` file and error went away, JDK10+Tomcat8.5 – Whome Apr 03 '19 at 18:21
  • 2
    Eclipse foundation has taken over JavaEE development. `javax.activation` has moved to `jakarta.activation` per https://wiki.eclipse.org/New_Maven_Coordinates – Jmini Feb 12 '20 at 07:03
5

I guess it can be useful. I have these additional packages in my soap project when switch from Java 8 to 10. Gradle:

compile "javax.xml.bind:jaxb-api:2.3.0"
compile "javax.activation:activation:1.1"
compile "com.sun.xml.bind:jaxb-impl:2.3.0"
compile "com.sun.xml.bind:jaxb-core:2.3.0"
compile "com.sun.xml.ws:rt:2.3.0"
compile "com.sun.xml.ws:jaxws-rt:2.3.0"
Svetopolk
  • 337
  • 5
  • 14
5

Just for other people with the same exception coming here:

This problem can also occur if you use a web server such as tomcat and if you need the activation jar to be present there as well. One possible solution is to put it in the lib folder of tomcat (or to use the common.loader functionality).

Markus Barthlen
  • 389
  • 4
  • 15
  • 3
    Thank you so much, it really helped me out. Just downloaded from https://mvnrepository.com/artifact/javax.activation/activation/1.1.1 and added to my project build path (school project, can't use maven). – Felipe Wagner Feb 14 '19 at 22:46
  • @markus-barthlen Thank you! That was just what I have been looking for for a few days! Now my `NoClassDefFoundError: javax/activation/DataSource` is gone :) – Kaj Hejer Nov 17 '19 at 17:26
-4

I had the same problem. After changing the project jdk, it works for me.

Change project jdk to 8.

Ardent Coder
  • 3,777
  • 9
  • 27
  • 53
Ibrahim A.
  • 45
  • 2
  • I don't know why they've downvoted you. This solved my problem. Thank you – Lucía Feb 25 '21 at 14:46
  • 3
    This solution is being downvoted because while downgrading the JDK works, it's a bad idea to to so. Java 8 isn't really supported any more. This just opens up the door to a number of other issues, not to mention security risks. – SapuSeven Feb 07 '22 at 10:23