我使用maven-jaxb2-plugin从xsd生成jaxb注释类.我有很多像这样的xsd文件:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="A3">
<xs:complexType>
<xs:sequence>
<xs:element name="loginPartner">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="login"/>
<xs:element type="xs:string" name="password"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="A3">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="errorCode"/>
<xs:element type="xs:string" name="errorDescription"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
当我运行maven插件时,它给了我一个错误:
[ERROR]解析模式时出错.位置[file:schema1.xsd {10,16}].org.xml.sax.SAXParseException:'A3'已经定义
有没有什么办法解决这一问题?实际上我有很多XSD代表来自/来自服务器的请求/响应消息.我想简化创建,验证,解析消息.也许还有另一种解决方案吗?
我有一个basic.xsd和另外两个A.xsd和B.xsd。A.xsd并B.xsd转换为两个不同的 java 包,因此我需要同一插件的两个 Maven 执行。
两个 XSD 都引用basic.xsd一些共享类。如果basic.xsd来自不同的项目,我可以通过使用episodes防止重复的类来很好地解决这个问题。
但我怎样才能参考当前的项目呢?
我第一次执行该插件是仅生成basic.xsd其自己的 java 命名空间中的类。之后 和 的执行者A.xsd应该B.xsd了解 生成的内容basic.xsd。
我可以以某种方式指出生成的剧集basic.xsd吗?
有点像
<episodes><episodeFile>basicXSD.episode</episodeFile</episodes>会很好,但据我所知,我只能添加依赖项...:-(
我正在尝试重用已经编译和可用的类.这看起来可以通过声明绑定到预先存在的类来实现,如下面的示例绑定提取:
<jaxb:bindings schemaLocation="MyExample.xsd">
<jaxb:bindings node="//xs:simpleType[@name='MySimpleType']">
<jaxb:class ref="com.example.MySimpleType" />
</jaxb:bindings>
<jaxb:bindings node="//xs:complexType[@name='MyComplexType']">
<jaxb:class ref="com.example.MyComplexType" />
</jaxb:bindings>
</jaxb:bindings>
Run Code Online (Sandbox Code Playgroud)
问题是虽然复杂的类型工作得很好,但简单的类型被忽略并且仍然生成....
我尝试了各种不同的符号(例如scd),但在Simple Types上没有成功.
任何想法或帮助非常欢迎....
我正在使用 Maven jaxb2 插件从 xsd 文件生成 Java 类。最近我遇到了问题,我的模式文件列表变得非常长,我将它们全部写在shemaFiles标签中作为逗号分隔值,并且该行本身很长,我担心将来它会影响代码的可读性并成为错误原因。那么有没有什么解决方案可以将文件写入单独的标签中,例如:
<schemaFilesList>
<schemaFile>SharedResources/xsd/Common.xsd</schemaFile>
<schemaFile>SharedResources/xsd/Another.xsd</schemaFile>
....
</schemaFilesList>
Run Code Online (Sandbox Code Playgroud)
这是我现在的代码:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<extension>true</extension>
<schemaDirectory>target/xsd</schemaDirectory>
<!-- I have really long list of files here, in different directories-->
<schemaFiles>
SharedResources/xsd/Common.xsd,SharedResources/xsd/Messaging/EmailService.xsd, .....
</schemaFiles>
</configuration>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
提前致谢。
我使用maven JaxB插件从XSD生成源。
插件的详细信息如下,
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.3</version>
Run Code Online (Sandbox Code Playgroud)
XSD中定义的枚举有两个值,
<simpleType name="MyEnum">
<restriction base="xsd:string">
<enumeration value="SimpleText" />
<enumeration value="ComplexText" />
</restriction>
</simpleType>
Run Code Online (Sandbox Code Playgroud)
生成的代码在枚举值的工作边界之间添加下划线。例如:“ SimpleText”在枚举中为SIMPLE_TEXT。
生成的代码,
@XmlType(name = "MyEnum")
@XmlEnum
public enum MyEnum {
@XmlEnumValue("SimpleText")
SIMPLE_TEXT("SimpleText"),
@XmlEnumValue("ComplexText")
COMPLEX_TEXT("ComplexText");
private final String value;
MyEnum(String v) {
value = v;
}
public String value() {
return value;
}
public static MyEnum fromValue(String v) {
for (MyEnum c: MyEnum.values()) {
if (c.value.equals(v)) {
return c;
}
}
throw new IllegalArgumentException(v);
}
Run Code Online (Sandbox Code Playgroud)
}
当枚举在不同位置用下划线分隔相同文本时,会出现此问题。例如
<simpleType name="MyEnum">
<restriction base="xsd:string"> …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用来自GitHub https://github.com/highsource/maven-jaxb2-plugin/releases的 jvnet maven-jaxb2-plugin的示例JAXB Maven项目。我正在使用最新版本0.13.0并下载了maven-jaxb2-plugin-sample-jaxbplugins-0.13.0-maven-src.zip
我通过命令行成功运行了mvn clean install。但是,当我将其导入Eclipse Luna时,出现了如下错误消息:
目标org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.0:generate的执行默认值:执行org.jvnet.jaxb2.maven2:maven-jaxb2-plugin:0.13.0时缺少必需的类:生成:com / sun / xml / bind / api / ErrorListener
有趣的是,我仍然可以使用Maven工具在Maven安装中运行并获取生成的类。但是错误消息在那里使我烦恼。那是一些Eclipse错误还是什么?请帮忙。
这是pom.xml的核心部分
<dependencies>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.2.11</version>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-runtime</artifactId>
<version>0.9.0</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.13.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<args>
<arg>-XtoString</arg>
<arg>-Xequals</arg>
<arg>-XhashCode</arg>
<arg>-Xcopyable</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.9.0</version>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Run Code Online (Sandbox Code Playgroud) 我无法让 AutoNameResolution 在 maven-jaxb2-plugin 中工作。下面是我的pom文件
<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>
<args>
<arg>-XautoNameResolution</arg>
</args>
<schemaLanguage>WSDL</schemaLanguage>
<generatePackage>com.commp.soap.service</generatePackage>
<schemas>
<schema>
<url>https://urltowsdl</url>
</schema>
</schemas>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚我哪里出错了。我在错误中得到的只是"A class/interface with the same name is already in use. Use a class customization to resolve this conflict."
因为我正在使用第三方 wsdl,我不会使用其中的大多数功能,我只想要一个简单的自动解析,而不是为我不使用的东西编写绑定。
我也尝试过 apache cxf。
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>stock-quote-service</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${project.basedir}/src/main/generated_java</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${project.basedir}/src/main/resources/wsdl/consume.wsdl</wsdl>
<wsdlLocation>http://usrltoWsdl</wsdlLocation>
<serviceName>Consumer</serviceName>
<extraargs>
<extraarg>-verbose</extraarg>
<extraarg>-p</extraarg>
<extraarg>com.projects.webservicex.service</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution> …Run Code Online (Sandbox Code Playgroud) 我正在尝试从多个 xsd 文件生成 java 类。但我收到这个错误。
org.xml.sax.SAXParseException; ...“somelement”已定义
我认为这是由于常见类型包含多次。
如何使用maven生成java类?
我的目录中有以下架构:
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) 我有这个XSD:(片段)
<xs:complexType name="complexA">
<xs:sequence>
<xs:element ref="abstractA" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:element name="abstractA" abstract="true"/>
<xs:element name="concreteA" type="concreteComplexA" substitutionGroup="abstractA"/>
<xs:complexType name="concreteComplexA">
<xs:attribute name="class" type="classId" use="required"/>
<xs:attribute name="property" type="namingId" use="required"/>
<xs:attribute name="value" type="xs:string" use="required"/>
</xs:complexType>
Run Code Online (Sandbox Code Playgroud)
JAXB输出一个叫做的类,concreteComplexA我可以让它输出concreteA名称吗?
该XSD是第三方所以它不能被修改.
谢谢!
你做.
我必须在 Ant 脚本中使用 JAXB 从 XML 架构文件生成类。当我以默认方式执行此操作时,一切都很顺利。后来我意识到我需要每个类的值构造函数。我尝试使用 XJC 的值构造函数插件,但是当我运行 Ant 脚本时出现错误:
BUILD FAILED
c:\HOME\plt\owf2-testing\EdytorScenariuszy\build.xml:17:
java.util.ServiceConfigurationError: com.sun.tools.xjc.Plugin: Provider org.jvnet.jaxb2_commons.plugin.value_constructor.ValueConstructorPlugin not a subtype
at java.util.ServiceLoader.fail(ServiceLoader.java:214)
at java.util.ServiceLoader.access$300(ServiceLoader.java:164)
at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:352)
at java.util.ServiceLoader$1.next(ServiceLoader.java:428)
at com.sun.tools.xjc.Options.findServices(Options.java:957)
at com.sun.tools.xjc.Options.getAllPlugins(Options.java:374)
at com.sun.tools.xjc.Options.parseArgument(Options.java:688)
at com.sun.tools.xjc.Options.parseArguments(Options.java:809)
at com.sun.tools.xjc.XJC2Task._doXJC(XJC2Task.java:474)
at com.sun.tools.xjc.XJC2Task.doXJC(XJC2Task.java:457)
at com.sun.tools.xjc.XJC2Task.execute(XJC2Task.java:380)
at com.sun.istack.tools.ProtectedTask.execute(ProtectedTask.java:103)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
Run Code Online (Sandbox Code Playgroud)
这是我的 Ant脚本:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<project name="EdytorScenariuszy" default="createClasses">
<taskdef name="xjc" classname="com.sun.tools.xjc.XJCTask">
<classpath>
<pathelement path="lib/jaxb-xjc.jar"/>
<pathelement path="lib/jaxb-impl.jar"/>
<pathelement path="lib/jaxb2-value-constructor.jar"/>
</classpath>
</taskdef>
<target name="clean">
<delete dir="src/xml" />
</target>
<target name="createClasses" …Run Code Online (Sandbox Code Playgroud)