你如何在Java 11中调用schemagen? [英] How do you invoke schemagen in Java 11?

查看:314
本文介绍了你如何在Java 11中调用schemagen?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据Oracle文档,作为JEP 320的一部分,将从JDK中删除schemagen工具( http:/ /openjdk.java.net/jeps/320 )。
JEP指向现在提供缺失工具的Maven工件。 JEP中工件的坐标是错误的,更新的坐标可以在这个问题的答案中找到:
我应该在我的Maven项目中使用哪些工件用于JAXB RI?

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 supply the missing tools. The coordinates of the artifacts are wrong in the JEP, updated coordinates are found in an answer to this question: Which artifacts should I use for JAXB RI in my Maven project?

然而,缺少的是如何调用工具。 JEP中指向的shell脚本位于JAXB-RI Git存储库中。但是,这些脚本仍然没有文档,很难调用。该git repo中的构建指令表明它是使用标准的mvn clean install构建的,但是它不会产生与此处文档中使用的bin文件夹匹配的输出结构: https://javaee.github.io/jaxb-v2/doc/user-guide /ch04.html#tools-schemagen

What is missing however is how to invoke the tools. There are shell scripts pointed to in the JEP that are in the JAXB-RI Git repository. However those scripts remain undocumented and difficult to invoke. The build instructions in that git repo indicated it is built with a standard "mvn clean install", however that does not produce an output structure that matches the 'bin' folder used in the documentation here: https://javaee.github.io/jaxb-v2/doc/user-guide/ch04.html#tools-schemagen

理想情况下,我想从Gradle运行schemagen,避免使用shell脚本,因为它们不是从maven依赖项中获取的。

Ideally I would like to run schemagen from Gradle, avoiding the shell scripts as they are not obtained from the maven dependency.

我当前的尝试,改编自调用旧的schemagen.exe的工作版本,如下所示:

My current attempt, adapted from a working version that called the old schemagen.exe, looks like this:

('real'build.gradle文件中有更多内容用于指定我的应用程序的依赖项等。)

(There is more in the 'real' build.gradle file to specify my application's dependencies, etc.)

configurations {
  schemagenTool
}
dependencies {
  schemagenTool "org.glassfish.jaxb:jaxb-jxc:${jaxbVersion}"
}
task schemaGen(type: Exec, dependsOn: [compileJava,configurations.schemaGenTool]) {
  workingDir projectDir
  executable 'java'

  doFirst {
    file('build/Schemas').mkdirs()
    args '--module-path', "${configurations.schemaGenTool.asPath}",
         '-m', 'jaxb.jxc/com.sun.tools.jxc.SchemaGeneratorFacade',
         // Note: automatic module name is NOT com.sun.tool.jxc
         // as documented
         // Args to schemagen (these worked for the schemagen.exe)
         '-d', 'build/Schemas',
         '-classpath', "${compileJava.destinationDir}${File.pathSeparator}${configurations.compile.asPath}",
         "src/main/java/path/to/my/ModelClass.java"
         //println "\nschemagen: ${args.join(' ')}\n"
  }

  doLast {
    // Above creates "build/Schemas/schema1.xsd" (despite printing a different path!)
    // Rename it
    def destFile = file('build/Schemas/model.xsd')
    destFile.delete()
    if (!file('build/Schemas/schema1.xsd').renameTo(destFile)) {
      throw new GradleException("Failed to write new build/Schemas/model.xsd")
    }
  }
}

然而,那个导致错误:

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


推荐答案

这个问题似乎与 jaxb - *:2.3.0 版本有关 - #jaxb-v2 / issues / 1168 。此外,这将通过已知问题

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 -


请尝试 2.4.0-b180725.0644 - 这是使用java.xml.bind模块(9,10)处理
JDK的JPMS模块化RI和没有它的那些(11-ea)

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)

尝试从同一链接下载二进制分发。

这篇关于你如何在Java 11中调用schemagen?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆