How do you invoke schemagen in Java 11?

前端 未结 3 1835
渐次进展
渐次进展 2021-02-09 17:25

According to Oracle documentation the schemagen tool is removed from the JDK as part of JEP 320 (http://openjdk.java.net/jeps/320). That JEP points to Maven artifacts that now s

相关标签:
3条回答
  • 2021-02-09 17:50

    Schemagen and xjc shell scripts are only put into binary distribution in ./bin directory.

    For build tools there are plugins out there (Maven / Gradle) which does invoke schemagen and xjc APIs, providing user with simple configuration.

    Your attempt to invoke com.sun.tools.jxc.SchemaGeneratorFacade manually is also correct, here is similar example for Maven. However you are probably putting 2.3.0 on module path, which has a split package problem. Putting on classpath will resolve the issue for 2.3.0. Next release of JAXB will be JPMS ready and have module descriptors declared. You can try the beta build (2.4.0-b180725.0644), here is a correct set of dependencies:

    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-runtime</artifactId> <!--jaxb runtime-->
    </dependency>
    
    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-xjc</artifactId> <!--java generation-->
    </dependency>
    
    <dependency>
      <groupId>org.glassfish.jaxb</groupId>
      <artifactId>jaxb-jxc</artifactId> <!--schema generation-->
    </dependency>
    
    0 讨论(0)
  • 2021-02-09 17:56

    If trying to use the schemagen in the jaxb-ri download directly, note the JAXB_PATH in schemagen.bat is inconsistent with the mod directory in the jaxb-ri.zip file.

    E.g. to use schemagen.bat:

    • As at now, download jaxb-ri-2.3.1.zip from https://maven.java.net/content/repositories/releases/com/sun/xml/bind/jaxb-ri/2.3.1/ (the 2.4.0-betas also had the mod/javax.activation-api.jar missing)

    • Use these steps to run schemagen.bat, setting JAXB_HOME as appropriate:

           set JAXB_HOME=C:\Java\jaxb-ri-2.3.1
           set CLASSPATH=%JAXB_HOME%/mod/relaxng-datatype.jar;%JAXB_HOME%/mod/javax.activation-api.jar
           %JAXB_HOME%\bin\schemagen.bat -cp myjar1.jar;myjar2.jar -d target com.company.ClassName1 com.company.ClassName2
      

    (This was against JDK 11)

    0 讨论(0)
  • 2021-02-09 18:06

    The issue seems to be known with the jaxb-*:2.3.0 version - #jaxb-v2/issues/1168. Additionally, this would be resolved with a future release as marked in the known issues of jaxb running over java-9.

    You can resolve this following the comment -

    Please try 2.4.0-b180725.0644 - this is JPMS modularized RI working on JDKs with java.xml.bind module (9,10) and those without it (11-ea)

    or try downloading the binary distribution from the same link.

    0 讨论(0)
提交回复
热议问题