我有一个xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<!-- The xml file -->
我正在使用带有maven的jaxb从xsd生成类:
<plugin>
<groupId>org.jvnet.jaxb2.maven2</groupId>
<artifactId>maven-jaxb2-plugin</artifactId>
<version>0.8.0</version>
<configuration>
<schemaDirectory>src/main/resources/xsd</schemaDirectory>
<bindingDirectory>src/main/resources/xsd</bindingDirectory>
<generatePackage>be.fgov.minfin.bbf.business.fileprocessing.jaxb</generatePackage>
<encoding>UTF-8</encoding>
<strict>false</strict>
<extension>true</extension>
<plugins>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics</artifactId>
<version>0.6.2</version>
</plugin>
<plugin>
<groupId>org.jvnet.jaxb2_commons</groupId>
<artifactId>jaxb2-basics-annotate</artifactId>
<version>0.6.2</version>
</plugin>
</plugins>
<args>
<arg>-Xannotate</arg>
<arg>-XtoString</arg>
</args>
</configuration>
<executions>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
文件生成正确,但文件是用编码Cp1252生成的,为什么?当我正在尝试编译时,我正在为内部的“é”字符编码UTF-8异常时出现一个不可映射的字符。
我正在设置:
${project.build.sourceEncoding}
我的主pom.xml中的变量为UTF-8 ..
答案 0 :(得分:1)
我们使用codehaus jaxb2插件,它有encoding-option ::
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>xjc_qshgv</id>
<phase>generate-sources</phase>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
...
<encoding>${file.encoding}</encoding>
...
</configuration>
</execution>
</executions>
</plugin>