小编Sid*_*Sid的帖子

如何在运行时以编程方式添加xjc插件?

我在运行时使用XJC从xsd生成JAXB类.但默认情况下,maxLengthxsd中的限制未注释.

我找到了一个处理这个问题的插件,krasa-jaxb-tools.我已经将依赖项添加到我的POM中,但我似乎无法将该插件添加到XJC进程中.

我正在使用jaxb-xjc工具的2.2.11版.这是我的依赖项:

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-xjc</artifactId>
    <version>2.2.11</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-impl</artifactId>
    <version>2.2.11</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-core</artifactId>
    <version>2.2.11</version>
</dependency>

<dependency>
    <groupId>com.sun.xml.bind</groupId>
    <artifactId>jaxb-jxc</artifactId>
    <version>2.2.11</version>
</dependency>

<dependency>
    <groupId>com.github.krasa</groupId>
    <artifactId>krasa-jaxb-tools</artifactId>
    <version>1.3</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)

我正在尝试实例化插件,配置它并将其传递给generateCode(Plugins[] extensions, ErrorListener errorListener)我的S2JJAXBModel模型上的方法,但它似乎没有任何影响.这是我的代码:

SchemaCompiler schemaCompiler = XJC.createSchemaCompiler();
schemaCompiler.forcePackageName(packageRoot);

// JAXB Plugin used to get the proper @Size annotations on all fields.
JaxbValidationsPlugins jaxbValidationPlugin = new JaxbValidationsPlugins();

// Build up list of options for the plugin.
// First option must be the name of …
Run Code Online (Sandbox Code Playgroud)

java xsd jaxb xjc

3
推荐指数
1
解决办法
913
查看次数

标签 统计

java ×1

jaxb ×1

xjc ×1

xsd ×1