XmlBeans使用ANSI编码生成Java源文件
我正在使用XmlBeans 2.6.0编译一些包含希腊单词枚举的XSD文件:XmlBeans使用ANSI编码生成Java源文件,java,utf-8,xsd,xmlbeans,Java,Utf 8,Xsd,Xmlbeans,我正在使用XmlBeans 2.6.0编译一些包含希腊单词枚举的XSD文件: <xs:simpleType name="t_series_report"> <xs:restriction base="xs:string"> <xs:enumeration value="Γενική"/> <xs:enumeration value="Ειδική"/> </xs:restriction>
<xs:simpleType name="t_series_report">
<xs:restriction base="xs:string">
<xs:enumeration value="Γενική"/>
<xs:enumeration value="Ειδική"/>
</xs:restriction>
</xs:simpleType>
有没有办法强迫XmlBeans将生成的Java文件保存为UTF-8而不是ANSI?我们在使用XmlBeans的maven任务编译包含希腊“Omega”的模式时遇到了类似的问题 问题是XMLBeans(至少从2.5.0版开始)总是使用Javas平台默认编码,这只能通过使用
-Dfile.encoding=UTF-8
调用JVM来设置
对于我们的Maven项目,解决方案是不使用插件;相反,我们使用exec
插件调用XMLBeans,因此我们可以控制编码。下面是pom.xml
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>exec-2.1.0</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dfile.encoding=${project.build.sourceEncoding}</argument>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
<classpath/>
<argument>org.apache.xmlbeans.impl.tool.SchemaCompiler</argument>
<argument>-src</argument>
<argument>${project.build.directory}/generated-sources</argument>
<argument>-srconly</argument>
<argument>-d</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-javasource</argument>
<argument>1.6</argument>
<argument>${basedir}/src/main/2.1.0/schema/</argument>
<argument>src/main/2.1.0/config/FooBar_v2.1.0.xsdconfig</argument>
</arguments>
</configuration>
</execution>
但这显然只有在所有源文件都是UTF-8的情况下才有效 您是作为Maven插件还是通过命令行(scomp)调用XMLBeans?@Gyro Gearless:作为ant任务谢谢,ant-Dfile.encoding=UTF-8构建XMLBeans成功了
[xmlbean] C:\projects\myproject\workspace\prj\build\xmlbeans\test\src\com\company\project\schema\myschematype\cl\cle\ext\TMyType.java:61: illegal character: \8220
[xmlbean] static final int INT_ΓΕ�?ΙΚΉ = 1;
[xmlbean]
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>exec-2.1.0</id>
<phase>generate-sources</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>java</executable>
<arguments>
<argument>-Dfile.encoding=${project.build.sourceEncoding}</argument>
<argument>-classpath</argument>
<!-- automatically creates the classpath using all project dependencies,
also adding the project build directory -->
<classpath/>
<argument>org.apache.xmlbeans.impl.tool.SchemaCompiler</argument>
<argument>-src</argument>
<argument>${project.build.directory}/generated-sources</argument>
<argument>-srconly</argument>
<argument>-d</argument>
<argument>${project.build.directory}/classes</argument>
<argument>-javasource</argument>
<argument>1.6</argument>
<argument>${basedir}/src/main/2.1.0/schema/</argument>
<argument>src/main/2.1.0/config/FooBar_v2.1.0.xsdconfig</argument>
</arguments>
</configuration>
</execution>
ant -Dfile.encoding=UTF-8 build-or-whatever