čtvrtek 24. září 2009

TeamCity, maven and encoding problems

I's been a while since my last post (haven't been doing smth interesting – just coding, building and surfing) so it is the high time to add smth. Too late, on the production environment, we have noticed that there is a problem with encoding in a name, but all the other text on an HTML page had no encoding problem. Strange, so we were looking for the source of this problem. My fellow noticed that the source of the names are included in a XML file under the /WEB-INF/conf/ of our war file. He noticed that the XML prolog has windows-1250 encoding set, but the content was UTF-8 encoded. Looking to the source XML file he noticed, that it is encoded correctly (windows-1250). So we identified the problem to be in a build system. We are using TeamCity with maven and the agent (building the war file) runs on a Linux system with UTF-8 file encoding. Before I continue, here comes the maven configuration part that was used to copy the war resources:
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <warName>web_isc</warName>
        <webResources>
            <resource>
                <directory>etc</directory>
                <targetPath>WEB-INF</targetPath>
                <filtering>true</filtering>
                <includes>
                    <include>conf/*.*</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>
The problem is in the filtering feature set to true, because the file is loaded using the platform encoding, that is unfortunately UTF-8 for our Linux system, thus wrong. Though, I was looking for an option to specify encoding for the maven war plugin, but there is no such option available so far. The workaround for this missing feature is to include only specific files that need to be filtered and exclude that doesn't need to be. Luckily, there was no need to included the incorrectly converted file in the filtering feature, so we ended up with the following setting that works :)
<plugin>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <warName>web_isc</warName>
        <webResources>
            <resource>
                <directory>etc</directory>
                <targetPath>WEB-INF</targetPath>
                <filtering>true</filtering>
                <includes>
                    <include>conf/spring.xml</include>
                    <include>conf/webapp.properties</include>
                </includes>
            </resource>
            <resource>
                <directory>etc</directory>
                <targetPath>WEB-INF</targetPath>
                <filtering>false</filtering>
                <includes>
                    <include>conf/*.*</include>
                </includes>
                <excludes>
                    <exclude>conf/spring.xml</exclude>
                    <exclude>conf/webapp.properties</exclude>
                </excludes>
            </resource>
        </webResources>
    </configuration>
</plugin>
Happy mavenizing...

Žádné komentáře:

Okomentovat