标签: jaxb2-maven-plugin

使用WSDL中的jaxb2-maven-plugin生成类

我无法配置jaxb2-maven-plugin从WSDL生成Java类以及所有存在于同一标准目录中的多个XSD文件src/main/xsd.

如何使用内联XSD的jaxb2 maven插件?只是因为答案正确地建议使用wsdl插件配置中的参数,但该问题确实与内联XSD有关,而我的XSD是外部的.

此处列出插件目标参数.

我的插件配置是:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>1.5</version>
    <executions>
        <execution>
            <id>xjc</id>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <packageName>com.x.y.model</packageName>
        <wsdl>true</wsdl>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

我正在测试它,mvn -X clean jaxb2:xjc但插件忽略.wsdl了调试输出中看到的

[DEBUG] accept false for file c:\projects\foo\src\main\xsd\service.wsdl
[DEBUG] accept true for file c:\projects\foo\src\main\xsd\datatypes.xsd
[DEBUG] accept true for file c:\projects\foo\src\main\xsd\more-datatypes.xsd
Run Code Online (Sandbox Code Playgroud)

java jaxb maven jaxb2-maven-plugin

17
推荐指数
5
解决办法
8万
查看次数

为什么 jaxb2-maven-plugin xjc 使用 Corretto jdk11.0.15_9 失败,但使用 Temurin jdk-11.0.14.1+1 则失败

自从将我的 jdk 升级到 Corretto jdk11.0.15_9 以来,jaxb2-maven-plugin 的 xjc 目标失败了。使用 Temurin jdk-11.0.14.1+1 运行时,该问题不会出现。我在 Windows 10 上使用 maven 3.8.5 运行它。

命令:

> set JAVA_HOME=C:\Corretto\jdk11.0.15_9
> mvn jaxb2:xjc

[INFO] Scanning for projects...
[INFO]
[INFO] -----------------< com.example >------------------
[INFO] Building example 1.0.0-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- jaxb2-maven-plugin:2.5.0:xjc (default-cli) @ example ---
[INFO] Created EpisodePath [C:\Workspace\example\target\generated-sources\jaxb\META-INF\JAXB]: true
[INFO] Created EpisodePath [C:\Workspace\example\target\generated-sources\jaxb\META-INF\JAXB]: true
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  0.764 s
[INFO] Finished at: 2022-04-21T15:24:15+02:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed …
Run Code Online (Sandbox Code Playgroud)

java xjc maven jaxb2-maven-plugin corretto

12
推荐指数
1
解决办法
9961
查看次数

使用 Maven 插件从 XSD/WSDL 生成 Jakarta 4.0.0 的 Java 代码

我浪费了很多天的时间试图弄清楚,看起来非常简单的事情(从 WSDL/XSD 生成代码)怎么会如此极其复杂。有什么办法吗?我觉得我已经尝试过所有这些,在不同的版本中使用不同的 jaxb 绑定和不同版本的实现

我尝试使用以下插件:

<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
Run Code Online (Sandbox Code Playgroud)
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
Run Code Online (Sandbox Code Playgroud)
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>

Run Code Online (Sandbox Code Playgroud)

没有插件能够输出 jakarta 注释并且总是失败,因为某些 javax.xml 注释或 com.sun.* 类丢失。此时我正在考虑自己编写一个插件,因为这很荒谬,我只需要一个简单的 POJO 和一些注释,并且不想在 xsd 或 wsdl 更改时自己编写它们。

你们在 Jakarta 4 中使用过哪些方法?

xml maven-jaxb2-plugin jaxb2-maven-plugin jaxws-maven-plugin

12
推荐指数
1
解决办法
1万
查看次数

是否有生成Builders的JAXB插件?

您是否了解为生成的JAXB类生成Builder模式类的任何优秀JAXB插件?使用JAXB生成的类编写域是非常讨厌的.我看到有人在2010年写回了一个插件,但它没有使用最新的maven插件jaxb2-maven-plugin,它还要求你为每个不健壮的模式类型指定绑定.

java xml jaxb2 jaxb2-maven-plugin

11
推荐指数
2
解决办法
7871
查看次数

如何使用jaxb2-maven-plugin在源文件夹中生成java类?

我使用jaxb2-maven-plugin来生成java类.有插件属性:

<plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.3</version>
            <executions>
                <execution>
                    <id>xjc</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- The package of your generated sources -->
                <packageName>com.bcap.me.JaxB</packageName>
                <sources>
                    <source>src/main/resources/xsds/pos.xsd</source>
                </sources>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

运行mvn clean compile插件后,在target\classes\com\bcap\me\JaxB目录中创建类.但我需要在源文件夹(包)中有类:src\main\java\com\bcap\me\JaxB 如何做到这一点?

更新 我添加outputDirectory属性,但我不确定这种方法的正确性:

<!--<packageName>com.bcap.me.JaxB</packageName>-->
<outputDirectory>src/main/java/com/bcap/me/JaxB</outputDirectory>
Run Code Online (Sandbox Code Playgroud)

UPDATE

我解决了我的情况:

  <execution>
                        <id>xjc_pos</id>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <!-- The package of your generated sources -->
                            <packageName>com.bcap.me.JaxB</packageName>
                            <outputDirectory>src/main/java</outputDirectory>
                            <sources>
                                <source>src/main/resources/xsds/pos.xsd</source>
                            </sources>
                            <generateEpisode>false</generateEpisode>
                            <clearOutputDir>false</clearOutputDir>
                        </configuration>
                    </execution>
Run Code Online (Sandbox Code Playgroud)

感谢@ulab

java jaxb jaxb2-maven-plugin

11
推荐指数
1
解决办法
9093
查看次数

JAXB无法为XBRL生成Java类

我正在尝试为XBRL中定义的类型生成Java类.

我的构建过程基于Maven 2,这是我的试验.我只粘贴build部分,它依赖于一些属性:

package 是我的目标包的名称

catalog是目录的路径和文件名.因为我没有互联网连接,我有amny条目,但我认为这些都是必要的

-- TR9401 for XBRL resources --
SYSTEM http://www.xbrl.org/2003/XLink http/www.xbrl.org/2003/xl-2003-12-31.xsd
SYSTEM http://www.w3.org/1999/xlink http/www.xbrl.org/2003/xlink-2003-12-31.xsd
Run Code Online (Sandbox Code Playgroud)

xsd.path 是XSD所在的目录

xsd.file 是以下极简主义XSD的文件名

     <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
       <xs:import namespace="http://www.xbrl.org/2003/instance"
        schemaLocation="http://www.xbrl.org/2003/xbrl-instance-2003-12-31.xsd"/>
     </xs:schema>
Run Code Online (Sandbox Code Playgroud)

我试过的所有插件都无法导入xl:nonEmptyURI.

但是xl映射到http://www.xbrl.org/2003/XLink(在我的目录中)哪个导入 <import namespace="http://www.w3.org/1999/xlink" schemaLocation="xlink-2003-12-31.xsd"/>定义 nonEmptyURI

怎么了?我该如何解决?

Apache CXF

        <plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-xjc-plugin</artifactId>
            <executions>
                <execution>
                    <id>generate-sources</id>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>xsdtojava</goal>
                    </goals>
                    <configuration>
                        <xsdOptions>
                            <xsdOption>
                                <catalog>${catalog}</catalog>
                                <xsd>${xsd.path}/${xsd.file}</xsd>
                                <packagename>${package}</packagename>
                            </xsdOption>
                        </xsdOptions>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

失败了

parsing a schema...

[ERROR] src-resolve: Cannot resolve the name 'xl:nonEmptyURI' …
Run Code Online (Sandbox Code Playgroud)

jaxb xbrl maven-jaxb2-plugin jaxb2-maven-plugin cxf-xjc-plugin

9
推荐指数
1
解决办法
2万
查看次数

从 maven-jaxb2-plugin 0.14.0 迁移到 jaxb2-maven-plugin 2.5.0

分享一下我的移民经历

<plugin>
   <groupId>org.jvnet.jaxb2.maven2</groupId>
   <artifactId>maven-jaxb2-plugin</artifactId>
   <version>0.14.0</version>
Run Code Online (Sandbox Code Playgroud)

<plugin>
   <groupId>org.codehaus.mojo</groupId>
   <artifactId>jaxb2-maven-plugin</artifactId>
   <version>2.5.0</version>
Run Code Online (Sandbox Code Playgroud)

我们使用原始插件从 WSDL 文件生成源代码。有人请求使用 Java 11 而不是 Java 8,更改后原始插件生成了警告。

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/D:/mr/org/glassfish/jaxb/jaxb-runtime/2.3.0/jaxb-runtime-2.3.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Run Code Online (Sandbox Code Playgroud)

由于这个问题仍然被报告为 maven-jaxb2-plugin 中的错误,并且自 2018 年以来该插件没有更新,因此我们决定移动 mojo 插件。

原始执行情况如下:

<execution>
    <id>uniqa</id> …
Run Code Online (Sandbox Code Playgroud)

java migrate maven-jaxb2-plugin jaxb2-maven-plugin

9
推荐指数
1
解决办法
4800
查看次数

使用org.springframework.oxm jaxb2marshaller附加CDATA

我使用jaxb2marshaller将少量元素用CDATA封送到XML时遇到了大麻烦.我已经完成了以下解决方案:

JAXB使用CDATA编组解组

如何使用JAXB生成CDATA块?

还有更多,但找不到合适的解决方案.他们要么告诉切换到旧的JAXB实现,要么使用MOXY.但是,这不是我的要求.我使用OXM库在下面实现了两个类,并希望生成一个XML,其中很少有元素需要附加CDATA.

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

@Configuration
public class AppConfig {
    @Bean
    public Processor getHandler(){
      Processor handler= new Processor();
      handler.setMarshaller(getCastorMarshaller());
      handler.setUnmarshaller(getCastorMarshaller());
      return handler;
    }
    @Bean
    public Jaxb2Marshaller getCastorMarshaller() {
      Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
      jaxb2Marshaller.setPackagesToScan("com.pom.dom.whatever.model");
      Map<String,Object> map = new HashMap<String,Object>();
      map.put("jaxb.formatted.output", true);
      jaxb2Marshaller.setMarshallerProperties(map);
          return jaxb2Marshaller;
    }
} 
Run Code Online (Sandbox Code Playgroud)

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import org.springframework.oxm.Marshaller;
import org.springframework.oxm.Unmarshaller;

public class Processor {
    private Marshaller marshaller;
    private Unmarshaller unmarshalling; …
Run Code Online (Sandbox Code Playgroud)

java spring marshalling jaxb2-maven-plugin spring-boot

8
推荐指数
1
解决办法
1403
查看次数

JAXB schemagen不引用剧集文件中的类

我实际上正在使用架构第一种方法,但是我遇到了"不祥的" JAXB Map问题的障碍!并通过切换到这个代码的第一种方法来解决它.现在,我想在其他模块中重用此类型,并通过从生成的模式创建一个剧集文件来继续我的模式第一种方法.不幸的是,生成的剧集文件是空的.这是我尝试过的:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>2.2</version>
    <executions>
        <execution>
            <id>schemagen</id>
            <goals>
                <goal>schemagen</goal>
            </goals>
            <phase>generate-sources</phase>
        </execution>
    </executions>
    <configuration>
        <outputDirectory>${project.build.outputDirectory}</outputDirectory>
        <generateEpisode>true</generateEpisode>
        <transformSchemas>
            <transformSchema>
                <uri>http://some/schema/types</uri>
                <toPrefix>core</toPrefix>
                <toFile>core-types.xsd</toFile>
            </transformSchema>
        </transformSchemas>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

这为我生成了以下架构:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:core="http://some/schema/types" targetNamespace="http://some/schema/types" version="1.0">
  <xs:element name="Map" type="core:MapType"/>

  <xs:complexType name="MapType">
    <xs:sequence>
      <xs:element maxOccurs="unbounded" minOccurs="0" name="entries" nillable="true" type="core:EntryType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="EntryType">
    <xs:sequence>
      <xs:element name="key" type="xs:anyType"/>
      <xs:element name="value" type="xs:anyType"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)

以及包含此内容的剧集文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns1:bindings version="2.1" xmlns:ns1="http://java.sun.com/xml/ns/jaxb"/>
Run Code Online (Sandbox Code Playgroud)

我尝试使用schemagen standalone(版本2.2.11),结果类似.https://jaxb.java.net/2.2.4/docs/schemagen.htmlhttp://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/schemagen-mojo.html上的文档接缝表明这应该是它,但我无法弄清楚我做错了什么.

java jaxb jaxb2 schemagen jaxb2-maven-plugin

6
推荐指数
1
解决办法
467
查看次数

生成的 XSD 中的空行

我正在尝试使用 jaxb2-maven-plugin(2.5.0 版)从一些 Java 类生成模式文件。我得到的 schema1.xsd 文件没有任何警告,但它包含额外的空行:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0">

  <xs:complexType name="sampleRequest">

    <xs:sequence>

      <xs:element minOccurs="0" name="someField" type="xs:string"/>

    </xs:sequence>

  </xs:complexType>

</xs:schema>
Run Code Online (Sandbox Code Playgroud)

我找不到任何原因或方法来配置这种行为(http://www.mojohaus.org/jaxb2-maven-plugin/Documentation/v2.2/schemagen-mojo.html)。到目前为止,我使用的是非常简单的配置:

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.5.0</version>
            <executions>
                <execution>
                    <goals>
                        <goal>schemagen</goal>
                    </goals>
                    <phase>generate-resources</phase>
                    <configuration>
                        <includes>
                            <include>path/to/my/package/*.java</include>
                        </includes>
                        <outputDirectory>${project.build.directory}/schemas</outputDirectory>
                    </configuration>
                </execution>
            </executions>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

我做错了什么还是有什么方法可以配置输出?我认为这不是编码问题,因为空行上实际上有一些缩进空格,而不仅仅是换行符:

在此处输入图片说明

我正在使用 JDK 11

java xsd jaxb2-maven-plugin

5
推荐指数
1
解决办法
209
查看次数