質問

I've got an xsd:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- The xml file -->

and I'm generating classes from that xsd with jaxb with maven:

<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>

The files are generated correctly, but the files are generated with encoding Cp1252, why? I'm getting an unmappable character for encoding UTF-8 exception for the "é" characters inside when I'm trying to compile.

I'm setting the:

${project.build.sourceEncoding}

variable in my main pom.xml to UTF-8..

役に立ちましたか?

解決

We use codehaus jaxb2 plugin and it has 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>
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top