Saša
Saša

Reputation: 4798

filtering JavaScript files by using Maven hide files from Jetty

I have strange problem with a Maven2.2.1 and JavaScript. The problem occured when I was trying to filter one JavaScript file according to different profiles I am running. My Maven code is near this:

        ...
        <resource>    
            <filtering>true</filtering>
            <directory>${basedir}/src/main/resources</directory>
            <includes>
                <include>settings-file.js</include>
            </includes>
            <targetPath>
                ${build.directory}/${build.finalName}/www/wc/js
            </targetPath>
        </resource>
         ...
        <profiles>
        <profile>
        <id>final</id>
        <properties>
            ...
            <web.setting.baseUrl>http://www.base.com</web.setting.baseUrl>
            ...
        </profile>                 
        </profiles>
        ...

I expect file "settings-file.js" to be filtered and all occurances of, for example, ${web.setting.baseUrl} to be changed when I call

mvn clean install -Pfinal

but it doesn't happend when file "settings-file.js" is put in the <targetDir>, so I moved it to src/main/resources expecting it to override an existing file - but it still doesn't happend. I resolved it with deleting file from original location and placing it in resources folder and editing maven pom.xml file (as it is shown in the listing).

Now I have new awkward problem. When I start my web-application with

mvn jetty:run 

and navigate to the page that is using "settings-file.js" it brakes because it does not see this file. It is now placed where it should be and properly filtered, but in some reason not visible to jetty. Other *.js files are there. I can see them if I type their url in browser, but only "settings-file.js" is not visible.

How can I resolve this problem?

Upvotes: 0

Views: 1738

Answers (1)

J&#246;rn Horstmann
J&#246;rn Horstmann

Reputation: 34024

In a maven web application, javascript files usually reside under src/main/webapp, to filter these you have to configure the webResources configuration of the war plugin. The default target is the root of the war file.

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.1</version>
    <configuration>
        <webResources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/webapp</directory>
                <includes>
                    <include>settings-file.js</include>
                </includes>
            </resource>
        </webResources>                    
    </configuration>
</plugin>

Upvotes: 1

Related Questions