5

I downloaded JAXB 2.3.0.1 and JavaBeans Activation Framework (JAF) 1.2.0 (based on the answer to this question). I extracted all JAR files to the same directory, then run the following command within that directory:

java -cp jaxb-api.jar;jaxb-core.jar;jaxb-impl.jar;javax.activation-1.2.0.jar
    -jar jaxb-xjc.jar [xjc-arguments]

The above command fails with the following message:

java.lang.NoClassDefFoundError: javax/activation/DataSource
    ...
Caused by: java.lang.ClassNotFoundException: javax.activation.DataSource

I have verified that class exists within the javax.activation-1.2.0.jar file. I have also tried using the new (to Java 9+) arguments -p . --add-modules java.activation, but that fails with the following error message:

Error occurred during initialization of boot layer
java.lang.modules.ResolutionException: Modules jaxb.core and jaxb.impl export package com.sun.xml.bind.marshaller to module java.activation

If I try a combination of -cp and --add-modules, I get a different boot layer initialization error. Does anyone know how to get XJC to run using a Java 9+ platform?

My specific use case is OpenJDK 11 on Windows.

Jeff G
  • 4,470
  • 2
  • 41
  • 76
  • 1
    Try [downloading the version](https://search.maven.org/search?q=a:javax.activation%20g:com.sun.activation) they've asked people to migrate to - `a:javax.activation g:com.sun.activation` and make sure to reference the correct jar names. Since the `DataSource` class in the logs seems to be [right there](https://github.com/eclipse-ee4j/jaf/blob/master/activation/src/main/java/javax/activation/DataSource.java) in the artifact. – Naman Oct 03 '18 at 01:33
  • 3
    You can't specify both -cp and -jar at the same time, I assume you mean to put jaxb-xjc.jar on the class path and specify its main class instead. – Alan Bateman Oct 03 '18 at 07:23
  • @nullpointer I downloaded the version you linked, but it is binary identical to the version I was already using (verified via cryptographic hash). – Jeff G Oct 03 '18 at 17:33
  • 2
    Upgrade to `jaxb-api` version 2.3.1, then you don't have to explicitly include JAF anymore. – Jesper Oct 05 '18 at 07:35

1 Answers1

4

The primary issue was that the java executable doesn't support specifying both the -cp and -jar command-line arguments at the same time. Thanks to Alan Bateman for that information!

Therefore, the correct way to get this to work is by using the following command:

java -cp javax.activation-1.2.0.jar;jaxb-xjc.jar com.sun.tools.xjc.XJCFacade
    [xjc-arguments]

In order to simplify running XJC, open bin/xjc.bat (extracted from jaxb-ri-2.3.0.zip), and edit the command line to match the above call.

Jeff G
  • 4,470
  • 2
  • 41
  • 76