这可能是这个问题的重复(避免编译器对xjc生成的代码的警告),但由于我不太熟悉XJC/JAXB自定义绑定的特性,我可能会认为我可能误解了上述问题.
我的问题看起来很简单 - 如何@SuppressWarnings("all")在生成的JAXB类中添加注释?我们的项目有0个警告政策,在JAXB生成步骤之后,我们最终会发出350多个警告,这些警告只是可怕的噪音.
我希望XJC上有一个简单的标志,或者至少提供这样的信息的简单方法,但我找不到任何.
从我在旅行中看到的情况来看,人们会做以下事情之一:
以前,我们通过在单独的Eclipse项目中推送与XML相关的代码然后禁用项目上的警告/错误来解决这个问题.现在,作为代码整合/重构的一部分,我们已经重新调整了一些东西,不再拥有这种奢侈品.
对于这样一个看似微不足道的问题,真的没有优雅的解决方案吗?任何反馈/想法都非常感谢.
FWIW,我们的项目使用Ant作为构建系统.
我有一个xsd架构,我正在从中生成一些java类.我正在使用jaxb代代相传.
我希望能够生成一个带注释的类@XmlRootElement,但我希望@XmlRootElement name属性与生成的类的名称不同.
在我的xsd中,我定义了以下内容:
<xs:element name="customer">
<xs:complexType>
<xs:sequence>
....
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
这段代码生成以下java类:
@XmlRootElement(name = "customer")
public class Customer {
...
}
Run Code Online (Sandbox Code Playgroud)
name的name属性@XmlRootElement与生成的Class的名称相同.我希望生成的类名是CustomerRequest.
我已经尝试使用该jaxb:class定义来更改classe名称.实际上,这个选项改变了类名但删除了@XmlRootElement注释,我需要它存在.
以下xsd:
<xs:element name="customer">
<xs:complexType>
<xs:annotation>
<xs:appinfo>
<jaxb:class name="CustomerRequest"/>
</xs:appinfo>
</xs:annotation>
<xs:sequence>
</xs:sequence>
</xs:complexType>
</xs:element>
Run Code Online (Sandbox Code Playgroud)
生成这个类:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "customer", propOrder = {
})
public class CustomerRequest {
}
Run Code Online (Sandbox Code Playgroud)
如何在@XmlRootElement不丢失注释的情况下使注释的属性名称与生成的类名称不同?
解决方案更新: 用户Xstian使用外部绑定提出了正确的解决方案.仅供进一步参考,我将使用内联绑定转换的解决方案更新我自己的帖子:
<xs:element name="customer">
<xs:complexType>
<xs:annotation>
<xs:documentation>Request object for the operation that checks if a …Run Code Online (Sandbox Code Playgroud) 我有许多由JAXB的xsd2java生成的类.我需要在编译时使用特定注释对所有这些类进行注释(例如使用lombok注释).有没有办法做到这一点,例如一些代码生成工具?
我正在使用命令行 (xjc.bat) 中的“jaxb-ri”构建基于 xsd 的 java 类。我想使用 jaxb2-annotate_plugin 在 XmlType 注释中设置命名空间,但我不知道如何将此插件添加到 xjc 类路径并激活它。
这是我的外部 bindings.xjb 文件:
<jxb:bindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
xmlns:annox="http://annox.dev.java.net"
jxb:extensionBindingPrefixes="xjc annox"
version="2.1">
<jxb:bindings schemaLocation="myschema.xsd" node="/xs:schema">
<jxb:bindings node="xs:complexType[@name='MyType]">
<annox:annotateClass>@javax.xml.bind.annotation.XmlType(namespace="urn:myschematwo")</annox:annotateClass>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
Run Code Online (Sandbox Code Playgroud)
我的命令行是:
D:/jaxb-ri/bin/xjc.bat -p "com.jaxb.mypackage" -d
"D:/myproject/src/main/java" D:/myschema.xsd -b "D:/bindings.xjb"
-extension
Run Code Online (Sandbox Code Playgroud)
当我执行此命令时,我收到一条错误消息,指出不支持“ http://annox.dev.java.net ”。
提前致谢。
我想在生成“Doc”类之前生成“@java.lang.SuppressWarnings("all")”。
问题:jaxb2-annotate-plugin 不生成注释。
我的 pom.xml:
...
<build>
<plugins>
<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>
<configuration>
<extension>true</extension>
<arguments>-Xannotate</arguments>
<args>
<arg>-Xannotate</arg>
</args>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-annotate-plugin-test-annox-annotations</artifactId>
</plugin>
</plugins>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>com.sun.codemodel</groupId>
<artifactId>codemodel</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
<dependency>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.4</version>
</dependency>
<dependency>
<groupId>com.sun.codemodel</groupId>
<artifactId>codemodel</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>${jaxb-api.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>${jaxb.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-xjc</artifactId> …Run Code Online (Sandbox Code Playgroud)