Search code examples
eclipsemavenjbosspropertiesdisplaytag

displaytag.properties location in a maven web project


In a maven web project (developed with Eclipse on JBoss), I have put the file displaytag.properties

paging.banner.placement=both

in the following three locations:

/myapp/src/main/java/displaytag.properties

/myapp/src/main/resources/displaytag.properties

/myapp/src/displaytag.properties

However, the file is not recognized. It does not affect the produced table.

Any ideas how I could understand what is wrong?

From DisplayTag Configuration properties:

For the whole web application, create a custom properties file named displaytag.properties and place it in the application classpath (tipically into WEB-INF/classes). Displaytag will use the locale of the request object to determine the locale of the property file to use; if the key required does not exist in the specified file, the key will be loaded from a more general property file.

There is no WEB-INF/classes in my folder structure, since this folder was not created by Maven.

UPDATE:

I've found out the reason why my properties files were not copied from /myapp/src/main/resources/*.properties to WEB-INF/classes in the generated war file. I've had the following setting in my pom file:

<resources>
    <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
        <includes>
            <include>applicationContext.xml</include>
            <include>security-config.xml</include>
        </includes>
    </resource>
    <resource>
        <targetPath>WEB-INF/classes</targetPath>
        <filtering>false</filtering>
        <directory>../src/main/resources</directory>
        <excludes>
            <exclude>**/*.properties</exclude>
        </excludes>
    </resource>
</resources>

Solution

  • WEB-INF/classes is the location where the classes of a webapp are found at runtime, inside the generated war file. The goal of Maven is to generate this war file. Check if the file is indeed in the war file generated by Maven.

    The appropriate location for such a file in a Maven project is /myapp/src/main/resources/displaytag.properties. The files in this location are considered as resources which must be copied along with the classes in the generated artefact. If it's not the case, it means that the resources plugin isn't used, or is configured in a way that excludes this file or gets resources from another directory.