如何使cxf-xjc-plugin在utf-8中生成源 [英] how to make cxf-xjc-plugin generate sources in utf-8
问题描述
我尝试使用cxf-xjc-plugin在Maven项目中从xsd生成Java类.
I try to generate java classes from xsd in a maven project using cxf-xjc-plugin.
它运行正常,但是生成的源文件使用特定于平台的编码(在Windows pc上为cp1251)而不是utf-8.如果任何xsd类型在模式注释中包含非拉丁字符,则它们仅在该特定编码下才可读,并且编译器随后会抱怨[WARNING] /C:/.../SomeType.java:[17,4] unmappable character for encoding UTF-8
.
It runs fine, but the generated source files get platform specific encoding (cp1251 on a windows pc) instead of utf-8. If any xsd types contain non-latin characters in schema annotations, then they become readable only in that specific encoding and the compiler later complains with [WARNING] /C:/.../SomeType.java:[17,4] unmappable character for encoding UTF-8
.
请帮助我强制 utf-8 生成源.
Please help me force utf-8 for sources generation.
源编码设置为
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
构建插件的设置如下:
<build>
...
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-xjc-plugin</artifactId>
<version>2.7.0</version>
<configuration>
<extensions>
<extension>org.apache.cxf.xjcplugins:cxf-xjc-dv:2.7.0</extension>
<extension>net.java.dev.jaxb2-commons:jaxb-fluent-api:2.1.8</extension>
</extensions>
</configuration>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<goals>
<goal>xsdtojava</goal>
</goals>
<configuration>
<sourceRoot>${basedir}/target/generated-sources</sourceRoot>
<xsdOptions>
<xsdOption>
<extension>true</extension>
<xsd>${basedir}/src/main/resources/schemas/Policy.xsd</xsd>
<bindingFile>${basedir}/src/main/resources/schemas/Policy.xjb</bindingFile>
<extensionArgs>
<extensionArg>-Xdv</extensionArg>
<extensionArg>-Xfluent-api</extensionArg>
</extensionArgs>
</xsdOption>
</xsdOptions>
</configuration>
</execution>
</executions>
</plugin>
...
在阅读了xjc的一些较旧的问题之后,尤其是 CXF-4369 和 JAXB-499 我试图使用Maven项目属性<file.encoding>utf-8</file.encoding>
强制编码并设置了运行mvn -Dfile.encoding=utf-8 clean install
时的系统属性,但无济于事.
after having read through some older issues with xjc, particularly CXF-4369 and JAXB-499 I tried to force encoding with maven project property <file.encoding>utf-8</file.encoding>
and set a system property while running mvn -Dfile.encoding=utf-8 clean install
, but got nowhere.
推荐答案
我可以通过将以下条目添加到xsdOption元素中,使cxf-xjc-plugin在UTF-8中生成源:
I could make cxf-xjc-plugin generate sources in UTF-8 by adding the following entry to the xsdOption element:
<extensionArgs>
<arg>-encoding</arg>
<arg>UTF-8</arg>
</extensionArgs>
这篇关于如何使cxf-xjc-plugin在utf-8中生成源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!