Nep*_*daj 5 java xsd jaxb2-maven-plugin
我正在尝试使用 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
我最终通过利用以下解决方案解决方案maven-replacer-plugin:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>maven-replacer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>remove-empty-lines</id>
<phase>generate-resources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>${project.build.directory}/schemas/*.xsd</include>
</includes>
<token>\s*$</token>
<value/>
<regexFlags>
<regexFlag>MULTILINE</regexFlag>
</regexFlags>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)
使用 JDK 8 并且不maven-replacer-plugin使用我生成的 XSDjaxb2-maven-plugin看起来很合理:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:EchoService="http://example/EchoService" elementFormDefault="qualified" targetNamespace="http://example/EchoService" version="1.0">
<xs:element name="echoServiceRequest" type="EchoService:echoServiceRequest"/>
<xs:complexType name="echoServiceRequest">
<xs:sequence>
<xs:element name="message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
使用 JDK 11 且不使用由包含许多空行maven-replacer-plugin生成的 XSD :jaxb2-maven-plugin
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:EchoService="http://example/EchoService" elementFormDefault="qualified" targetNamespace="http://example/EchoService" version="1.0">
<xs:element name="echoServiceRequest" type="EchoService:echoServiceRequest"/>
<xs:complexType name="echoServiceRequest">
<xs:sequence>
<xs:element name="message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
使用 JDK 11 和maven-replacer-plugin我生成的 XSDjaxb2-maven-plugin看起来再次合理:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:EchoService="http://example/EchoService" elementFormDefault="qualified" targetNamespace="http://example/EchoService" version="1.0">
<xs:element name="echoServiceRequest" type="EchoService:echoServiceRequest"/>
<xs:complexType name="echoServiceRequest">
<xs:sequence>
<xs:element name="message" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Run Code Online (Sandbox Code Playgroud)
所以我猜测 /xjc/JDK 11 中有一个 bugjaxb2-maven-plugin导致空行。
我承认这是一个解决方案,而且maven-replacer-plugin非常旧,可能不再维护。
希望这对其他人有帮助。
| 归档时间: |
|
| 查看次数: |
209 次 |
| 最近记录: |