0

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?

2
  • It sounds like you're dealing with two different issues here. The first is that you're not sure how to get maven filtering to work the way you want it to. The second is that jetty isn't serving a javascript file the way you expect it to. Not sure about the filtering. The second issue could be permissions-related. Commented Dec 13, 2011 at 14:24
  • I just figured that it works with mvn jetty:run-war and mvn jetty:run-explode but not with mvn jetty:run as if the last one puts only original code to jetty container. The question is now how to make jetty:run goal to use filtered resource? Commented Dec 14, 2011 at 9:01

1 Answer 1

1

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>
Sign up to request clarification or add additional context in comments.

2 Comments

Nope, this doesn't make mvn jetty:run to work corectly. However, the file is now visible to the context, but not filtered.
Hey it helped but not entirely. See my next post for an explanation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.