本文介绍了“非法字符:\ 65279”尽管设置为UTF-8,但在Maven编译期间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用保存为UTF-8的文件编译Maven Java项目,该文件具有,但我从中的BOM字符中收到非法字符错误,尽管我同时拥有 project.build.sourceEncoding 以及 maven-compiler-plugin 编码设置为 UTF- 8

I am trying to compile a Maven Java project with files saved as UTF-8 that have a BOM, but I am getting an illegal character error from the BOM character in the despite I having both the project.build.sourceEncoding as well as the encoding of the maven-compiler-plugin set to UTF-8.

我错过了额外的设置吗?
我是否可以在不删除BOM的情况下进行编译(不允许对源进行任何更改,但我可以修改POM)?

Am I missing an additional setting?Can I even get this to compile without removing the BOM (not allowed to make any change to the source, but I can modify the POM)?

错误:

该物业:

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

该插件:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.1</version>
            <configuration>
                <encoding>UTF-8</encoding>
            </configuration>
        </plugin>
    </plugins>
</build>


推荐答案

如果它是UTF-8而不是UTF-16, BOM完全没有用处。它为什么放在那里?此外,只有Java在这里抱怨 - 而不是Maven。

If it's UTF-8 and not UTF-16, the BOM serves no purpose at all. Why is it put in there? Also, only Java is complaining here -- not Maven.

查看。

这篇关于“非法字符:\ 65279”尽管设置为UTF-8,但在Maven编译期间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 13:43