从 Maven 将 Eclipse 项目编码定义为 UTF-8

发布于 2024-09-29 18:16:32 字数 472 浏览 7 评论 0原文

我想将项目文件的编码设置为 UTF-8。

按照 maven 常见问题解答,我设置了 project.build.sourceEncoding< /code> 属性为 UTF-8。不幸的是,它没有效果。

然后,通过查看 m2eclipse JIRA,我尝试了通过定义编译器插件 sourceEncoding,但它不起作用,因为我尝试在单独的模块父 pom.xml 中执行此操作。

那么,有什么解决方案可以确保我的文件都是来自 maven 的 UTF-8 格式呢?

谢谢。

I want to have the encoding of my project's file to be set to UTF-8.

Following maven FAQ answer, I set the project.build.sourceEncoding property to UTF-8. unfortunatly, it has no effect.

Then, by looking at a m2eclipse JIRA, I tried a workaround by defining compiler plugin sourceEncoding, but it neither worked, as I try to do that in a separate module parent pom.

Then, what is the solution to ensure my files are all in UTF-8 from maven ?

Thanks.

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

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

发布评论

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

评论(3

你与清晨阳光 2024-10-06 18:16:32

(有点晚了)我用来避免继承 MacRoman 的解决方案/解决方法。

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <additionalConfig>
            <file>
              <name>.settings/org.eclipse.core.resources.prefs</name>
              <content>
                <![CDATA[eclipse.preferences.version=1${line.separator}encoding/<project>=${project.build.sourceEncoding}${line.separator}]]>
              </content>
            </file>
          </additionalConfig>
        </configuration>
      </plugin>
    </plugins>
  </build>

执行以下命令:

mvn eclipse:eclipse

归功于 史蒂文·卡明斯

(A bit late) Solution / workaround I'm using to avoid inheriting MacRoman.

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-eclipse-plugin</artifactId>
        <version>2.9</version>
        <configuration>
          <additionalConfig>
            <file>
              <name>.settings/org.eclipse.core.resources.prefs</name>
              <content>
                <![CDATA[eclipse.preferences.version=1${line.separator}encoding/<project>=${project.build.sourceEncoding}${line.separator}]]>
              </content>
            </file>
          </additionalConfig>
        </configuration>
      </plugin>
    </plugins>
  </build>

Execute the command below :

mvn eclipse:eclipse

Credits to Steven Cummings.

森罗 2024-10-06 18:16:32

只需指定

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

即可。

它过去不起作用 - 因此有其他答案 - 但这早在 2011 年就已修复。有关更多详细信息,请参阅 Eclipse 错误条目 343927

Just specifying

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

will do it.

It didn't use to work - hence the other answers - but this was fixed already back in 2011. For more details, see eclipse bug entry 343927.

依 靠 2024-10-06 18:16:32

Define Eclipse project encoding as UTF-8 from Maven

I don't know if you saw MNGECLIPSE-1782 but this is currently not supported, m2eclipse doesn't derive the project encoding from your POM. You'll have to set up the encoding manually under Eclipse (which can be done globally for the workspace via Preferences > General > Workspace).

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