How to generate JavaScript file from Java properties using Maven in Eclipse?

In the old Java web application, there are many keys in the property files for internationalization. JavaScript functions also use this key to display some messages.

In fact, this file is embedded in the HTML, dynamically generated on the JSP, which leads to an increase of approximately 400 Kbytes for each page request. To improve performance a bit, I generated JavaScript files with the key | value with content as follows:

var b = {
    keys: {
        "key.one": "value.one",
        "key.two": "value.two"
    }
};

The path to the JavaScript file is as follows:

Javascript files

Message properties files are located in the directory:

Message properties files

I need to read the message property files in the assembly to create JavaScript files. For this, I use exec-maven-pluginconfigured in this way:

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.3.2</version>
    <executions>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>java</goal>
            </goals>
        </execution>
    </executions>
    <configuration>
        <arguments>
            <argument>${project.build.directory}/${project.build.finalName}</argument>
        </arguments>
        <mainClass>com.brunocesar.build.GenerateI18NJSFiles</mainClass>
    </configuration>
</plugin>

GenerateI18NJSFiles JavaScript, maven build (: mvn clean compile war:exploded). Eclipse. SO, Eclipse lifecycle-mapping :

<plugin>
    <groupId>org.eclipse.m2e</groupId>
    <artifactId>lifecycle-mapping</artifactId>
    <version>1.0.0</version>
    <configuration>
        <lifecycleMappingMetadata>
            <pluginExecutions>
                <pluginExecution>
                    <pluginExecutionFilter>
                        <groupId>org.codehaus.mojo</groupId>
                        <artifactId>exec-maven-plugin</artifactId>
                        <versionRange>[${exec-maven-plugin.version},)</versionRange>
                        <goals>
                            <goal>java</goal>
                        </goals>
                    </pluginExecutionFilter>
                    <action>
                        <execute>
                            <runOnIncremental>false</runOnIncremental>
                        </execute>
                    </action>
                </pluginExecution>
            </pluginExecutions>
        </lifecycleMappingMetadata>
    </configuration>
</plugin>

Eclipse, Maven.

Eclipse (, m2e-wtp, , ) (, JBoss, Tomcat ..)?

+4

All Articles