Java 生成的XSD中的空行
我正在尝试使用jaxb2 maven插件(版本2.5.0)从一些Java类生成模式文件。我得到的schema1.xsd文件没有任何警告,但它包含额外的空行:Java 生成的XSD中的空行,java,xsd,jaxb2-maven-plugin,Java,Xsd,Jaxb2 Maven Plugin,我正在尝试使用jaxb2 maven插件(版本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="sampl
<?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>
我找不到任何原因或方法来配置此行为()。到目前为止,我使用的配置非常简单:
<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>
org.codehaus.mojo
我使用的是JDK 11通过使用maven replacer插件,我最终得到了以下解决方案:
<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>
使用JDK 11和不使用maven replacer插件
my XSD生成的jaxb2 maven插件
包含许多空行:
<?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>
所以我猜在jaxb2maven插件/xjc/JDK 11中有一个bug导致了空行
我承认这是一个变通解决方案,maven replacer plugin
非常古老,可能不再维护
希望这对其他人有所帮助。在从jdk 8升级到jdk 11和从2.0.0->2.2.4升级spring boot时遇到了同样的问题。找到解决方案了吗?我也有同样的问题,但在我的情况下,任何两个非空行之间都有三个空行。有人有解决办法吗?
<?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>
<?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>