windows - 由于 'ñ",无法使用 Maven 编译 XMLBean 生成的类

标签 windows eclipse maven encoding xmlbeans-maven-plugin

我正在处理一个项目,但我无法编译从 WSDL 生成 XMLBeans。

文件生成正常,但是当我想编译项目时,我有几个类有问题。

我猜,主要问题是类的名称有一个 ñAñoDocument.java 并且它无法编译。

[INFO] Compiling 998 source files to D:\workspace3\MyProject\my_module\target\classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] \workspace3\MyProject\my_module\src\main\java\com\mycompany\schema\AñoDocument.java:[17,18] illegal character: \65533
[ERROR] \workspace3\MyProject\my_module\src\main\java\com\mycompany\schema\AñoDocument.java:[20,63] illegal character: \65533
[ERROR] \workspace3\MyProject\my_module\src\main\java\com\mycompany\schema\AñoDocument.java:[20,77] <identifier> expected
[ERROR] \workspace3\MyProject\my_module\src\main\java\com\mycompany\schema\AñoDocument.java:[20,82] = expected
[ERROR] \workspace3\MyProject\my_module\src\main\java\com\mycompany\schema\AñoDocument.java:[20,83] ';' expected
....

Eclipse -> Project -> Properties -> Resource -> Text Encoding 中,我选中了“Inherit from container (Cp1252)”。

这是我项目的POM:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <parent>
      <artifactId>MyProject</artifactId>
      <groupId>com.mycompany</groupId>
      <version>1.0</version>
    </parent>

    <groupId>com.mycompany</groupId>
    <artifactId>my_module</artifactId>
    <version>1.0</version>
    <name>my_module</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>xmlbeans-maven-plugin</artifactId>
                <version>2.2.0</version>
                <executions>
                    <execution>
                       <phase>generate-sources</phase>
                        <goals>
                            <goal>xmlbeans</goal>
                        </goals>
                    </execution>
                </executions>
                <inherited>true</inherited>
                <configuration>
                    <schemaDirectory>downloads</schemaDirectory>
                    <noVDoc>true</noVDoc>
                    <noJavac>true</noJavac>
                    <sourceGenerationDirectory>src/main/java</sourceGenerationDirectory>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-clean-plugin</artifactId>
                <configuration>
                    <filesets>     
                        <fileset>
                        <directory>src/main/java</directory>
                            <includes>
                                <include>**/*.java</include>
                            </includes>
                        </fileset>
                    </filesets>
                </configuration>
            </plugin> 
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans</artifactId>
            <version>2.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.apache.xmlbeans</groupId>
            <artifactId>xmlbeans-xpath</artifactId>
            <version>2.2.0</version>
        </dependency>   

        <dependency>
            <groupId>net.sf.saxon</groupId>
            <artifactId>saxon</artifactId>
            <version>8.7</version>
        </dependency>

    </dependencies>

</project>

有人知道我该怎么做才能解决这个问题吗?

最佳答案

我认为问题不在于 ñ 字符本身。对于类名来说,这是一个完全有效的字符,如以下测试类所示(我知道它在 JDK 1.6 上打印为 true)。

public class Main {
    public static void main(String[] args) {
         System.out.println(Character.isJavaIdentifierPart('ñ'));
    }
}

您正在将文件保存在 Cp1252 中,它与 ASCII 字符的 UTF-8 兼容,但与非 ASCII 字符不兼容。然后你告诉 maven 你的源文件是用 UTF-8 编码的。这会导致 Maven 错误地读取 ñ 字符,当它将 ñ 解释为字符\65533 - the replacement character 时,它会出现在您的构建中。 .尝试在 Eclipse -> Project -> Properties -> Resource -> Text Encoding

下将资源编码更改为 UTF-8

关于windows - 由于 'ñ",无法使用 Maven 编译 XMLBean 生成的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6656355/

相关文章:

android - 顶级异常应用程序 :dexDebug --dex -no-optimize --output android studio

maven - 在 WEB-INF/lib 内的 JAR 中找不到 CDI 实例

c++ - 在 MFC 应用程序中,将文件从一个目录复制到另一个目录的最简单方法是什么?

java - Fxml 文件未在 Eclipse 中更新

eclipse - Tomcat 中的 native 库 UnsatisfiedLinkError + Windows + eclipse

Maven 与 MySQL 的依赖关系

java - 维护类似的Android项目

c++ - 无法将参数 5 从 'SIZE_T *' 转换为 'size_t *'——为什么?

regex - 在Perl中,如何匹配两个连续的回车符?

javascript - Node.js 本地主机 :3000 refuses to connect