标签: jaxb2-maven-plugin

schemagen.exe生成具有<xs:complexType>的非确定顺序的xsd模式

我使用org.codehaus.mojo jaxb2-maven-plugin为我的类生成xsd模式.插件站点 http://mojo.codehaus.org/jaxb2-maven-plugin/faq.html告诉,该插件使用JDK实用程序schemagen.exe进行生成. 问题是生成的xsd中的顺序未确定,并且取决于您运行插件的计算机.

public class One {
    public String field1;
}

public class Two {
    public String field2;
}
Run Code Online (Sandbox Code Playgroud)

并生成方案:

<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="two">
    <xs:sequence>
      <xs:element name="field2" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>  

  <xs:complexType name="one">
    <xs:sequence>
      <xs:element name="field1" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

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

但是,当我的同事经营一代时,他会得到另一个订单:

<xs:schema version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:complexType name="one">
    <xs:sequence>
      <xs:element name="field1" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>


  <xs:complexType name="two">
    <xs:sequence>
      <xs:element name="field2" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType> 

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

我们用

  • JDK 1.6.0_26
  • jaxb2-maven-plugin 1.3
  • jaxb-impl版本2.1.12(由插件使用)

有没有办法控制这个订单?

xsd jaxb schemagen jaxb2-maven-plugin

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

在编组jaxb时从根元素中删除xmlns属性

这可能与JAXB Marshaller有关 - 如何抑制xmlns命名空间属性?

但我的问题有点不同.我做常规的java编组,我的xsd没有名称空间.生成的xml也没有名称空间,除了根元素.

<?xml version="1.0" encoding="UTF-8"?><rootElement xmlns:ns2="unwanted namespace">
Run Code Online (Sandbox Code Playgroud)

unwanted namespace是从同一个项目另一个模式,我不知道这是为什么被拾起在这个阶段.

我的rootElement.java由jaxb2-maven-plugin生成,如下所示:

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"feed"
})
@XmlRootElement(name = "rootElement", namespace = "")
public class RootElement{
....
}
Run Code Online (Sandbox Code Playgroud)

在这一点上,我想要的是xmlns:ns2="unwanted namespace"从生成的xml中删除属性,我正在努力解决它.

我查看了我的package-info.java,它看起来像:

@javax.xml.bind.annotation.XmlSchema(namespace = "unwanted namespace", elementFormDefault =   javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package com.mypackage;
Run Code Online (Sandbox Code Playgroud)

我尝试添加他,-npajaxb2-maven-plugin由于某种原因它不会工作.我尝试了NamespaceMapper但这适用于更改前缀.我无法完全删除名称空间.这让我困扰了一天.

java xml jaxb xml-namespaces jaxb2-maven-plugin

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

maven-jaxb2-plugin用于多个模式的VS jaxb2-maven-plugin

我有多个xsd架构,我想解组到同一文件夹下的不同包中target/generated-sources/xjc.我尝试了两个插件,两者似乎都可以正常使用这两种配置但是在maven-jaxb2-plugin的情况下,eclipse插件会无限期地生成类(因为forceRegenerate= true)但是如果我没有指定forceRegenerate它就不会生成我运行时的第二和第三组课程mvn clean package我的配置是否有任何问题?

JAXB2 - Maven的插件

<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
    <execution>
        <id>xjc-scores</id>
        <goals>
            <goal>xjc</goal>
        </goals>
        <configuration>
            <packageName>com.generated.scores</packageName>
            <schemaDirectory>src/main/resources/schemas/scores</schemaDirectory>
        </configuration>
    </execution>
    <execution>
        <id>xjc-videos-ramp</id>
        <goals>
            <goal>xjc</goal>
        </goals>
        <configuration>
            <packageName>com.generated.ramp</packageName>
            <schemaDirectory>src/main/resources/schemas/ramp</schemaDirectory>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
    <execution>
        <id>xjc-schedules</id>
        <goals>
            <goal>xjc</goal>
        </goals>
        <configuration>
            <packageName>com.generated.schedules</packageName>
            <schemaDirectory>src/main/resources/schemas/schedules</schemaDirectory>
            <clearOutputDir>false</clearOutputDir>
        </configuration>
    </execution>
</executions>
<configuration>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

Maven的JAXB2-插件

<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
<executions>
    <execution>
        <id>xjc-scores</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>generate</goal>
        </goals>
        <configuration>
            <generatePackage>com.generated.scores</generatePackage>
            <schemaDirectory>src/main/resources/schemas/scores</schemaDirectory>
            <removeOldOutput>true</removeOldOutput>
        </configuration>
    </execution>
    <execution>
        <id>xjc-ramp</id>
        <phase>generate-sources</phase>
        <goals>
            <goal>generate</goal>
        </goals> …
Run Code Online (Sandbox Code Playgroud)

java eclipse maven maven-jaxb2-plugin jaxb2-maven-plugin

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

org.codehaus.mojo : jaxb2-maven-plugin : 1.6 --> API incompatibility was encountered

when using
jaxb2-maven-plugin from codehaus i get the following problem marker in eclipse the content of this marker contains the following:

Description Resource    Path    Location    Type
Execution configuration of goal org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc failed: An API incompatibility was encountered while executing org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc: java.lang.NoSuchMethodError: org.codehaus.plexus.util.DirectoryScanner.setupMatchPatterns()V
-----------------------------------------------------
realm =    plugin>org.codehaus.mojo:jaxb2-maven-plugin:1.6
strategy = org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy
urls[0] = file:/C:/develop/maven/repository/org/codehaus/mojo/jaxb2-maven-plugin/1.6/jaxb2-maven-plugin-1.6.jar
urls[1] = file:/C:/develop/maven/repository/org/slf4j/slf4j-jdk14/1.5.6/slf4j-jdk14-1.5.6.jar
urls[2] = file:/C:/develop/maven/repository/org/slf4j/slf4j-api/1.5.6/slf4j-api-1.5.6.jar
urls[3] = file:/C:/develop/maven/repository/org/slf4j/jcl-over-slf4j/1.5.6/jcl-over-slf4j-1.5.6.jar
urls[4] = file:/C:/develop/maven/repository/org/apache/maven/reporting/maven-reporting-api/2.2.1/maven-reporting-api-2.2.1.jar
urls[5] = file:/C:/develop/maven/repository/org/apache/maven/doxia/doxia-sink-api/1.1/doxia-sink-api-1.1.jar
urls[6] = file:/C:/develop/maven/repository/org/apache/maven/doxia/doxia-logging-api/1.1/doxia-logging-api-1.1.jar
urls[7] = file:/C:/develop/maven/repository/commons-cli/commons-cli/1.2/commons-cli-1.2.jar
urls[8] = file:/C:/develop/maven/repository/org/codehaus/plexus/plexus-interactivity-api/1.0-alpha-4/plexus-interactivity-api-1.0-alpha-4.jar
urls[9] = file:/C:/develop/maven/repository/backport-util-concurrent/backport-util-concurrent/3.1/backport-util-concurrent-3.1.jar
urls[10] …
Run Code Online (Sandbox Code Playgroud)

xsd jaxb xjc maven jaxb2-maven-plugin

5
推荐指数
2
解决办法
9432
查看次数

maven-jaxb2-plugin失败,JAXB版本属性必须存在

我有以下配置maven-jaxb2-plugin:

            <!-- https://mvnrepository.com/artifact/org.jvnet.jaxb2.maven2/maven-jaxb2-plugin -->
            <plugin>
                <groupId>org.jvnet.jaxb2.maven2</groupId>
                <artifactId>maven-jaxb2-plugin</artifactId>
                <version>0.13.2</version>
                <executions>
                    <execution>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <configuration>
                    <strict>false</strict>
                    <schemaLanguage>WSDL</schemaLanguage>
                    <generatePackage>com.mycompany.project.domain.wsdl</generatePackage>
                    <schemas>
                        <schema>
                            <url>url or file</url>
                        </schema>
                    </schemas>
                </configuration>
            </plugin>
Run Code Online (Sandbox Code Playgroud)

它失败了:

[ERROR] Error while parsing schema(s).Location [ file:/home/hasancansaral/workspace/company/domain/src/main/xsd/delivery.wsdl{2,366}].
Run Code Online (Sandbox Code Playgroud)

org.xml.sax.SAXParseException; systemId:file:/home/hasancansaral/workspace/company/domain/src/main/xsd/delivery.wsdl; lineNumber:2; columnNumber:366; 必须存在JAXB版本属性

如果我通过IntelliJ IDEA运行插件或做一个简单的操作,它没有什么区别mvn clean jax2b:generate.但是,使用可在此处找到的架构的操作是成功的,因此我怀疑我的wsdl架构实际上是格式错误的,我暂时无法公开,但可以通过消息提供(我知道它没有多大帮助按原样公开,但如果问题出现在模式中,我将在此处发布相关的问题部分).

注意: SOAP UI也会验证架构.

注2: 同样的错误是存在既jax2b-maven-pluginmaven-jax2b-plugin.

jaxb maven-plugin maven maven-jaxb2-plugin jaxb2-maven-plugin

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

如何在Java 11和Maven中运行XJC?

为了从XSD生成Java类(用于读取XML文件),我们使用了jaxb2-maven-plugin和Java8。

对于Java 11,我们遇到了很多问题...

哪些库和插件可以工作(今天),从而允许使用Java 11和Maven从XSD生成Java代码?如果可能,请指出不同的解决方案,例如使用cxf-xjc-plugin,jaxb2-Maven-Plugin和其他解决方案。

jaxb maven jaxb2-maven-plugin cxf-xjc-plugin java-11

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

如何在 JAXB2 maven 插件版本 2.4 中定义模式目录?

我正在尝试在 pom.xml 中定义架构的目录。我不断收到错误消息“此处不允许使用元素 schemaDirectory”。我猜这个版本不支持这个元素。那么在这个版本中如何定义我的模式目录呢?

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>2.4</version>
    <executions>
        <execution>
            <id>xjc</id>
            <goals>
                <goal>xjc</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <schemaDirectory>${project.basedir}src/main/resources</schemaDirectory>
        <outputDirectory>${project.basedir}src/main/java</outputDirectory>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

提前致谢!

java plugins pom.xml maven jaxb2-maven-plugin

5
推荐指数
2
解决办法
7549
查看次数

如何告诉 Maven 不要忽略导入的 XSD 中的命名空间属性?

我正在使用 mojohaus jaxb2-maven-plugin 从 xsd 模式文件生成 Java 源。我的 pom.xml 如下所示:

...    
<plugin>

            <groupId>org.codehaus.mojo</groupId>
            <artifactId>jaxb2-maven-plugin</artifactId>
            <version>2.5.0</version>
            <executions>
                <execution>
                    <id>xjc-1</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <packageName>my.first.package.types</packageName>
                        <sources>
                            <source>src/main/java/META-INF/wsdl/firstSchema.xsd</source>                                
                        </sources>                          
                    </configuration>
                </execution>
                <execution>
                    <id>xjc-2</id>
                    <goals>
                        <goal>xjc</goal>
                    </goals>
                    <configuration>
                        <packageName>my.second.package.types</packageName>
                        <sources>                                                       
                            <source>src/main/java/META-INF/wsdl/secondSchema.xsd</source>
                        </sources>
                        <clearOutputDir>false</clearOutputDir>              
                    </configuration>
                </execution>
            </executions>
            <configuration>
                <outputDirectory>src/main/javagen</outputDirectory>
            </configuration>
        </plugin>
Run Code Online (Sandbox Code Playgroud)

该插件配置应与此处找到的配置相对应。当我运行构建时,从第一个架构生成的源文件被放入第二个包中。谁能向我解释为什么会这样?这是一个错误还是我错过了什么?

非常感谢您的任何意见!

编辑:

我也尝试了 maven-jaxb2-plugin 。结果一样!所以这似乎是一个一般的专家问题。我的 maven-jaxb2-plugin 插件配置如下:

...
            <plugin>
            <groupId>org.jvnet.jaxb2.maven2</groupId>
            <artifactId>maven-jaxb2-plugin</artifactId>
            <version>0.14.0</version>
            <executions>
                <execution>
                    <id>first</id>
                    <goals>
                        <goal>generate</goal>
                    </goals>
                    <configuration>
                        <schemaIncludes>
                            <include>firstSchema.xsd</include>
                        </schemaIncludes>
                        <generatePackage>my.first.package.types</generatePackage>
                    </configuration>
                </execution>
                <execution>
                    <id>second</id>
                    <goals>
                        <goal>generate</goal>
                    </goals> …
Run Code Online (Sandbox Code Playgroud)

java xjc maven maven-jaxb2-plugin jaxb2-maven-plugin

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

jaxb2-maven-plugin 使用 xmlns 前缀生成 package-info.java

我想用 jaxb2-maven-plugin 生成 java 类。我正在使用以下配置:

pom.xml:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>jaxb2-maven-plugin</artifactId>
    <version>2.5.0</version>
    <executions>
        <execution>
            <id>SomeID</id>
            <goals>
                <goal>xjc</goal>
            </goals>
            <configuration>
                <extension>true</extension>
                <clearOutputDir>true</clearOutputDir>
                <sources>
                    <source>src/main/xsd/schema.xsd</source>
                </sources>
                <noGeneratedHeaderComments>true</noGeneratedHeaderComments>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

架构.xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://my.target.namespace/uri" 
    xmlns="http://my.target.namespace/uri" 
    elementFormDefault="qualified"
    attributeFormDefault="unqualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:h="http://my.uri.for.prefix.h"
    xmlns:f="http://my.target.namespace/uri">
    
    <xsd:import namespace="http://my.uri.for.prefix.h" schemaLocation="schema2.xsd"/> 
    
    <xsd:complexType name="FooType">
        <xsd:sequence>
            <xsd:element ref="h:something" minOccurs="0" maxOccurs="1"/>
        </xsd:sequence>
    </xsd:complexType>

    <xsd:element name="FooType" type="FooType" />
 
</xsd:schema>
Run Code Online (Sandbox Code Playgroud)

Jaxb2 插件正在为我生成以下package-info.java

@javax.xml.bind.annotation.XmlSchema(namespace = "http://my.target.namespace/uri", elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED)
package ...;
Run Code Online (Sandbox Code Playgroud)

但是,我想得到的是:

@javax.xml.bind.annotation.XmlSchema(namespace = "http://my.target.namespace/uri", xmlns = {
        @XmlNs(prefix="f", namespaceURI="http://my.target.namespace/uri"),
        @XmlNs(prefix="h", namespaceURI="http://my.uri.for.prefix.h")
}, …
Run Code Online (Sandbox Code Playgroud)

java jaxb xjc maven jaxb2-maven-plugin

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

Jaxb2 maven 插件从复杂类生成 xsd 时出现错误

我有一个案例,我有 35 个类,其中一些类在它们内部相互关联。例如;

Addendum.java


    @XmlType(name="addendum",namespace= GenericNameSpaceConstants.POLICY_NAMESPACE_URI)
@XmlAccessorType(XmlAccessType.FIELD)
public class Addendum implements Serializable {

    @XmlElement(name="changeNumber",nillable=false,required=true)
    private Long changeNumber;

    @XmlElement(name="changeTypeDesc",nillable=false,required=true)
    private String changeTypeDesc;

    @XmlElement(name="changeTypeId",nillable=false,required=true)
    private Integer changeTypeId;

}

Policy.java
    @XmlRootElement(name="policy",namespace=GenericNameSpaceConstants.POLICY_NAMESPACE_URI)
@XmlType(name="policy",namespace= GenericNameSpaceConstants.POLICY_NAMESPACE_URI)
@XmlAccessorType(XmlAccessType.FIELD)
public class Policy {

 @XmlElement(name="addendum",required=true,nillable=false)
    private Addendum addendum;
}

My jaxb schemage config in pom file like that

    <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>jaxb2-maven-plugin</artifactId>
                <version>2.2</version>
                <configuration>
                <createJavaDocAnnotations>false</createJavaDocAnnotations>
                <sources>       
                <source>
                ${project.basedir}\src\main\java\com\aegon\common\service\bean\
                </source>

                </sources>
                <verbose>true</verbose>
                <outputDirectory>${basedir}/src/main/resources/schemas</outputDirectory>
                <transformSchemas>
                <transformSchema>               
                            <toPrefix>pol</toPrefix>
                            <toFile>policy_model_v2.xsd</toFile>
                </transformSchema>
                </transformSchemas>
                <generateEpisode>true</generateEpisode>
                </configuration>
            <executions>
            <execution>
            <phase>generate-resources</phase>
            <goals>

            <goal>schemagen</goal>
            </goals>
            </execution>
            </executions>   
            </plugin>
Run Code Online (Sandbox Code Playgroud)

当我运行项目以生成资源或生成源阶段时。我收到此错误 …

jaxb jaxb2 maven jaxb2-maven-plugin

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