更改为 Maven 依赖项后,特殊字符变得混乱

发布于 2024-12-14 01:31:45 字数 634 浏览 4 评论 0原文

我正在编写一个项目,它可以从文件中读取日语字符并输出这些字符,并且工作得很好。
问题是,当我将其更改为 Maven(使用 Maven 3.03)项目时...并将每个 jar 都放在 Maven 依赖项中,然后运行我的项目,我发现每个日语字符都搞砸了。
例如,我得到如下输出:

���� 

我猜这是因为 Maven 编码属性,所以我尝试进行此更改,

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

其中我将默认的 project.reporting.outputencoding 属性更改为 UTF-8。我进行此更改是因为有人说它适用于 Maven 2.X,但可能不适用于 Maven 3.X...而实际上它根本不起作用。
所以我希望有人可以帮助我弄清楚如何设置属性并获得正确的输出?

谢谢

I am writing a project, which can read Japanese characters from file and do an output of those Chars, and works just fine.

Problem is, when I change it to a maven (Using Maven 3.03) projects... and have every jars in maven dependency, then run my project, I found every single Japanese Char messed up.

For Example, I have got outputs like:

���� 

I guess that's because the maven encoding properties, so I tried to make this change

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

In which I changed the default project.reporting.outputencoding property to UTF-8. I made this change because someone said it works for Maven 2.X but maybe not for Maven 3.X... and actually it doesn't work at all.

So I hope there's somebody can help me figure out how to set the properties and have the proper output?

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

猫弦 2024-12-21 01:31:45

听起来 Maven 正在过滤没有正确字符编码的属性文件。

您可能需要告诉 Maven 处理资源插件在处理资源时使用 UTF-8 编码。说明如下:

http://maven.apache.org /plugins/maven-resources-plugin/examples/encoding.html

Sounds like Maven is filtering your properties files without the correct character encoding.

You may need to tell the Maven process resource plug-in to use UTF-8 encoding while processing resources. Instructions for that are here:

http://maven.apache.org/plugins/maven-resources-plugin/examples/encoding.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文