标签: jaxb2-maven-plugin

在生成Jaxb类时,包被删除使用Maven和生成的maven包名称不正确

我尝试使用jaxb2-maven-plugin从XSD生成Jaxb类.

我能够在一个包中获取jaxb类,但我的其他包被删除了.这是什么原因?怎么过来这个?请你给个建议.

以下是我的尝试

<bulid>
    <pluginManagement>
    <plugins>
        <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>1.5</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>xjc</goal>
                </goals>
            </execution>
        </executions>
        <configuration>
            <schemaDirectory>src/main/xsd</schemaDirectory>
            <outputDirectory>src/main/java</outputDirectory>
        </configuration>
        </plugin>
    </plugins>
    </pluginManagement>
    </bulid>
Run Code Online (Sandbox Code Playgroud)

和xsd看起来像这样:

<?xml version="1.0" encoding="UTF-8"?><xsd:schema targetNamespace="com.test.jaxb.model" 
        xmlns:ns="com.test.jaxb.model" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="TestResults">
        <xsd:sequence>
            <xsd:element maxOccurs="unbounded" minOccurs="0" name="testSuites" type="Q1:TestSuiteRun"/>
        </xsd:sequence>
        <xsd:attribute name="testProject" type="xsd:string"/>
    </xsd:complexType>


    <xsd:complexType name="TestCaseRun">
        <xsd:complexContent>
            <xsd:extension base="Q1:TestRun">
                <xsd:sequence>
        <xsd:element name="result" type="Q1:Severity"/>
      <xsd:element maxOccurs="unbounded" minOccurs="0" name="variations" type="Q1:VariationRun">
                    </xsd:element>
                </xsd:sequence>
                <xsd:attribute name="variationCount" type="xsd:int"/>
            </xsd:extension>
        </xsd:complexContent>
    </xsd:complexType>

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

我给了targetNamespace ="com.test.jaxb.model"但是在生成之后我只能看到包名下的jaxb类:model.jaxb.test.com ..

为什么包名称反转,为什么我的其他包被删除?

java xsd jaxb maven jaxb2-maven-plugin

4
推荐指数
2
解决办法
5842
查看次数

如何使用 JAXB 自定义绑定自定义生成的 Java 对象的字段名称?

我正在尝试为下面的示例 xsd 生成 JAXB 生成的对象。

<xs:complexType name="AddressType">   
      <xs:sequence>   
        <xs:element name="USA" type="xs:string"/>   
      </xs:sequence>   
   </xs:complexType>  
Run Code Online (Sandbox Code Playgroud)

没有任何自定义绑定生成的类是

@XmlAccessorType(XmlAccessType.FIELD)   
@XmlType(name = "AddressType", propOrder = {   
    "usa"  
})   
public class AddressType {   

    @XmlElement(name = "USA", required = true)   
    protected String usa;   

    /**  
     * Gets the value of the usa property.  
     *   
     * @return  
     *     possible object is  
     *     {@link String }  
     *       
     */  
    public String getUSA() {   
        return usa;   
    }   

    /**  
     * Sets the value of the usa property.  
     *   
     * @param value  
     *     allowed …
Run Code Online (Sandbox Code Playgroud)

jaxb2 jaxb2-maven-plugin

4
推荐指数
1
解决办法
3608
查看次数

用于jaxb-maven-plugin的IntelliJ bindingDirectory

我想在一个单独的schema.xjb绑定文件中为schema.xsd生成的类型添加globalBinding.我正在使用IntelliJ并且不确定这个问题是maven还是Intellij正在做(因为这个例子在eclipse中按预期运行).我得到的错误是:

org.xml.sax.SAXParseException; systemId: file:/D:/Projects/Location/To/Project/src/main/resources/xsd/schema.xsd; lineNumber: 7; columnNumber: 10; vendor extension bindings (jaxb:extensionBindingPrefixes) are not allowed in the strict mode. Use -extension.
Run Code Online (Sandbox Code Playgroud)

这是我的pom.xml中的build元素:

<build>
    <plugins>
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>1.5</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                <!-- The name of your generated source package -->
                <packageName>com.my.model.example</packageName>
                    <schemaDirectory>${project.basedir}/src/main/resources/xsd</schemaDirectory>
                <!-- Well Intellij acts badly when it comes down to binding files, so there is that. -->
                <bindingDirectory>${project.basedir}/src/main/resources/xjb</bindingDirectory>
            </configuration>
        </plugin>

    </plugins>

</build>
Run Code Online (Sandbox Code Playgroud)

这是我的架构位于/ src/main/resources/xsd:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           id="SampleSchema"
           targetNamespace="http://sample.com/namespace"
           elementFormDefault="qualified"
           xmlns="http://sample.com/namespace"
        >

    <xs:element …
Run Code Online (Sandbox Code Playgroud)

jaxb intellij-idea maven jaxb2-maven-plugin

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

当 maxOccurs 大于 5000 时,jaxb2-maven-plugin 抛出异常

当我在旧版 xsd 上运行 jaxb2-maven-plugin 时,它会抛出此异常:

解析器的当前配置不允许将 maxOccurs 属性值设置为大于值 5,000

谷歌搜索此错误表明这是出于安全目的对 jaxp 施加的限制。可以在这样的代码中禁用它

SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING,false);
Run Code Online (Sandbox Code Playgroud)

但我需要在 Maven 中执行此操作。另外,xjc 有一个 -nv 开关来关闭此验证,这看起来是可行的方法。我无法更改 xsd。

在 jaxb2-maven-plugin 中传递 -nv 开关的语法是什么?

maven jaxb2-maven-plugin

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

是否有通用的方法在pom.xml中设置-D参数?

tl; dr:那么,有没有办法移动-D系统属性的定义并将其内化到pom.xml文件中?


我们目前正在-Djavax.xml.accessExternalSchema=all从命令行传递,mvn clean install -Djavax.xml.accessExternalSchema=all以使我的构建工作.我无法通过插件中的选项(jaxb2-maven-plugin 1.6),因为我们使用的版本不支持此版本,而且版本需要完全更改配置,我们将不会获得批准.

试图设置使用内的标签的值<properties>别处建议由下加入<project>标记:

<properties>
    <javax.xml.accessExternalSchema>all</javax.xml.accessExternalSchema>
</properties>
Run Code Online (Sandbox Code Playgroud)

但我仍然得到一个错误(转载如下),而通过命令行传递它不会.

Caused by: org.xml.sax.SAXParseException; 
systemId: jar:file:/e:/apache/maven/.m2/repository/com/sun/xml/bind/jaxb-xjc/2.2.7/jaxb-xjc-2.2.7.jar!/com/sun/tools/xjc/reader/xmlschema/bindinfo/binding.xsd; 
lineNumber: 52; columnNumber: 88; schema_reference: 
Failed to read schema document 'xjc.xsd', because 'file' access is not allowed due to restriction set by the accessExternalSchema property.
Run Code Online (Sandbox Code Playgroud)

maven jaxb2-maven-plugin

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

如何使用 jaxb2-maven-plugin 预定义 XSD 文件名

我使用下面的代码从带注释的 java 类生成 XSD。XSD 的默认名称始终为“schema1.xsd”。我应该如何仅使用该插件来预定义它?目前我使用 maven-antrun-plugin 进行文件重命名。插件手册不包含相关信息。

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>jaxb2-maven-plugin</artifactId>
  <version>2.3</version>
  <executions>
    <execution>
      <goals>
        <goal>schemagen</goal>
      </goals>
      <phase>generate-sources</phase>
      <configuration>
        <sources>
          <source>src/main/java/***some package***</source>
        </sources>
        <outputDirectory>${project.build.directory}/generated-sources/schemas</outputDirectory>
      </configuration>
    </execution>
  </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

java xsd jaxb maven jaxb2-maven-plugin

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

如何使用 Maven 从具有通用模式的多个 xsd 生成 java 类

我正在尝试从多个 xsd 文件生成 java 类。但我收到这个错误。

org.xml.sax.SAXParseException; ...“somelement”已定义

我认为这是由于常见类型包含多次。

如何使用maven生成java类?

我的目录中有以下架构:

xsd:

  • 示例_QualifyRS.xsd
  • 示例_QualifyRQ.xsd
  • 示例_Peble_CommonTypes.xsd
  • 示例_CommonTypes.xsd
  • 示例_SimpleTypes.xsd

示例_QualifyRS.xsd

<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.002" id="EXAMPLE2016.1">
    <xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
    <xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/>
    <xs:include schemaLocation="EXAMPLE_Peble_CommonTypes.xsd"/>
         <xs:element name="someelement">...</xs:element>
Run Code Online (Sandbox Code Playgroud)

示例_Peble_CommonTypes.xsd

<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.000" id="EXAMPLE2016.1">
    <xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
Run Code Online (Sandbox Code Playgroud)

示例_QualifyRQ.xsd

<xs:schema xmlns="http://www.example.org/EXAMPLE/2007/00" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/EXAMPLE/2007/00" elementFormDefault="qualified" version="1.001" id="EXAMPLE2016.1">
    <xs:include schemaLocation="EXAMPLE_CommonTypes.xsd"/>
    <xs:include schemaLocation="EXAMPLE_SimpleTypes.xsd"/>
    <xs:include schemaLocation="EXAMPLE_Peble_CommonTypes.xsd"/>
        <xs:element name="someelement">...</xs:element>
Run Code Online (Sandbox Code Playgroud)

这是我在 Maven 中生成类的方法

<plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.4</version>
                <executions>
                    <execution>
                        <id>example-schema</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>xjc</goal>
                        </goals>
                        <configuration>
                            <xsdPathWithinArtifact>xsd</xsdPathWithinArtifact>
                            <addGeneratedAnnotation>true</addGeneratedAnnotation>
                            <laxSchemaValidation>true</laxSchemaValidation>
                            <laxSchemaValidation>true</laxSchemaValidation>
                            <readOnly>true</readOnly>
                            <verbose>true</verbose>
                            <sources> …
Run Code Online (Sandbox Code Playgroud)

java xsd jaxb maven-jaxb2-plugin jaxb2-maven-plugin

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

jaxb2-maven-plugin XJB 中的错误:元素“绑定”的命名空间必须来自架构命名空间“

我试图将不同的名称空间分配给不同的 xsd 文件,并使用 jaxb2-maven 插件来构建由这些 xsd 文件定义的工件。

Maven 无法生成源并出现以下错误:The namespace of element 'bindings' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'

这是我的配置:

<jaxb:bindings 
xmlns:jaxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/jaxb 
                http://java.sun.com/xml/ns/jaxb/bindingschema_2_0.xsd"
version="2.1">

<jaxb:bindings schemaLocation="xsd/TheRequest.xsd" node="/xsd:schema">
    <jaxb:schemaBindings>
        <jaxb:package name="com.package.request" />
    </jaxb:schemaBindings>
</jaxb:bindings>

<jaxb:bindings schemaLocation="xsd/TheResponse.xsd" node="/xsd:schema">
    <jaxb:schemaBindings>
        <jaxb:package name="com.package.response" />
    </jaxb:schemaBindings>
</jaxb:bindings>

</jaxb:bindings>

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
targetNamespace="http://company.services.com" 
xmlns:tns="http://company.services.com" 
elementFormDefault="unqualified">

<xsd:complexType name="FindSomething">
    <xsd:sequence>
        <xsd:element name="TestMode" type="xsd:string" maxOccurs="1" minOccurs="0"/>
        <xsd:element name="Channel" type="xsd:string" maxOccurs="1" minOccurs="1"/>
        <xsd:element name="UserId" type="xsd:string" maxOccurs="1" minOccurs="1"/>
        <xsd:element name="Role" type="xsd:string" maxOccurs="1" minOccurs="0"/>
        <xsd:element name="Format" …
Run Code Online (Sandbox Code Playgroud)

xsd jaxb maven jaxb2-maven-plugin xjb

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

JAXB2如何直接使用WSDL url而不是.WSDL文件

我已经在我的项目中安装了 JAXB2 maven 插件。从我的 SOAP WebService 生成的 .WSDL 文件位于项目目录中,但我希望 JAXB2 直接使用 WSDL URL 而不是使用 .wsdl 文件。

soap soap-client maven-jaxb2-plugin jaxb2-maven-plugin

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

如何排除在 jaxb2-maven-plugin 2.5.0 版中生成剧集文件?

我使用jaxb2-maven-pluginxjc目标从一组 xsd 文件生成 Java 类。

一个最小的、完整的和可验证的例子是一个带有以下 pom.xml 文件的 Maven 项目:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.example</groupId>
  <artifactId>jaxb2-maven-episode-test</artifactId>
  <version>1.0</version>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.source>1.8</maven.compiler.source>
  </properties>

  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>jaxb2-maven-plugin</artifactId>
        <version>2.3.1</version>
        <executions>
          <execution>
            <id>xjc</id>
            <goals>
              <goal>xjc</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <sources>
            <source>${project.basedir}/src/main/resources/</source>
          </sources>
          <generateEpisode>false</generateEpisode>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>
Run Code Online (Sandbox Code Playgroud)

src/main/resources/文件夹中有一个名为example.xsd的文件(任何有效的 xsd 文件都可以):

<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://tempuri.org/PurchaseOrderSchema.xsd"
           targetNamespace="http://tempuri.org/PurchaseOrderSchema.xsd"
           elementFormDefault="qualified">
 <xsd:element name="PurchaseOrder" type="tns:PurchaseOrderType"/>
 <xsd:complexType name="PurchaseOrderType">
  <xsd:sequence>
   <xsd:element name="ShipTo" type="tns:USAddress" maxOccurs="2"/>
   <xsd:element name="BillTo" type="tns:USAddress"/> …
Run Code Online (Sandbox Code Playgroud)

xjc maven jaxb2-maven-plugin jaxb-episode

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