Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to externalize Strings to "resources" with Eclipse for a Maven project?

I am using Eclipse for developing a Maven project.

I tried to use the externalize Strings wizard in Eclipse. By default, the resulting messages.properties is placed within the "src/main/java" folder. Yet, when packaging my project with Maven, the properties file is thrown out from the created jar file. Therefore I tried to move the message.properties to the "src/main/resources" folder but it seems like Eclipse does not accept that!

I'd rather not modify my pom.xml since it is quite standardized in the enterprise. So is there a way to force Eclipse to accept having the properties file out of the "src/main/java"?

Thanks for your help.

like image 306
Jean Logeart Avatar asked Dec 30 '25 18:12

Jean Logeart


2 Answers

I created bug 369296 at eclipse.org for this, and in the process of doing that, I found a work-around. It turns out that the m2e plugin (which manages maven projects in eclipse) adds an exclusion filter of "**" to any resource directory. This exclusion filter prevents the NLS wizard from using that resource directory as its source folder.

So, to work around this issue, edit your build path in eclipse and remove the ** exclusion from the src/main/resources folder. Then, run the NLS wizard and do all the NLS-y things you want to do. Lastly, have m2e regenerate the project configuration - this will re-add the ** exclusion.

Hope this helps. It looks like they're going to fix my bug.

like image 66
Stephen Avatar answered Jan 02 '26 09:01

Stephen


If you are using spring, make sure that in your application servlet context you have:

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

In your JSP:

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:message key="whatever.key.from.message.file" />
like image 33
Ali Avatar answered Jan 02 '26 11:01

Ali



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!