簡體   English   中英

對於 Maven 項目,如何使用 Eclipse 將字符串外部化為“資源”?

[英]How to externalize Strings to “resources” with Eclipse for a Maven project?

我正在使用 Eclipse 開發 Maven 項目。

我嘗試在 Eclipse 中使用外部化字符串向導。 默認情況下,生成的messages.properties放在“src/main/java”文件夾中。 然而,當使用 Maven 打包我的項目時,屬性文件會從創建的 jar 文件中丟棄。 因此,我嘗試將 message.properties 移動到“src/main/resources”文件夾,但似乎 Eclipse 不接受!

我寧願不修改我的pom.xml ,因為它在企業中非常標准化。 那么有沒有辦法強制 Eclipse 接受“src/main/java”之外的屬性文件?

謝謝你的幫助。

為此,我在 eclipse.org 創建了錯誤 369296 ,在此過程中,我找到了解決方法。 事實證明,m2e 插件(在 eclipse 中管理 maven 項目)將“**”排除過濾器添加到任何資源目錄。 此排除過濾器可防止 NLS 向導將該資源目錄用作其源文件夾。

因此,要解決此問題,請在 eclipse 中編輯您的構建路徑,並從 src/main/resources 文件夾中刪除 ** 排除項。 然后,運行 NLS 向導並做所有你想做的 NLS 事情。 最后,讓 m2e 重新生成項目配置 - 這將重新添加 ** 排除項。

希望這可以幫助。 看來他們要修復我的錯誤了。

如果您使用的是 spring,請確保在您的應用程序 servlet 上下文中具有:

<resources mapping="/resources/**" location="/resources/" />

在您的 JSP 中:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:message key="whatever.key.from.message.file" />

After you use the externalize Strings wizard in Eclipse, it puts the property files in src/main/java, so move the property files to src/main/resources (either in eclipse with refactor/move or outside eclipse) and then recreate the eclipse通過從命令行在項目根文件夾中運行以下命令,使用 maven 的項目文件

mvn eclipse:eclipse

然后清理並刷新 eclipse 里面的項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM