Running resource filters when using jetty:run
Asked Answered
S

3

9

I'm using resource filtering on jsps, based on profiles. I'm also developing locally using mvn jetty:run, but the filtering phase does not run.

How can I perform filtering using the jetty plugin?


Configuration snippets:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
    <webResources>
        <resource>
            <directory>src/main/webapp</directory>
            <includes>
                <include>error.jsp</include>
            </includes>
            <filtering>true</filtering>
            <targetPath>/</targetPath>
        </resource>
    </webResources>
</configuration>
</plugin>

<profile>
    <id>jci</id>
    <activation>
        <activeByDefault>true</activeByDefault>
        <property>
            <name>jci</name>
        </property>
    </activation>
    <properties>
        <error.title>Some value here</error.title>
    </properties>
</profile>  
Stamin answered 26/7, 2009 at 20:14 Comment(2)
@Robert: Have you found any solution to this problem in the mean time? I was inclined to post a similar question when I came across yours...Virgina
Running jetty:deploy-war got me somewhat further, but still no real working solution.. Anyone have a real answer to this question?Virgina
P
6

You may want to use the jetty:run-exploded goal rather than jetty:run. From the documentation:

This goal first assembles your webapp into an exploded war file and then deploys it to Jetty.

This may ensure that the appropriate war lifecycle phases are executed before the server is started.

Also are you sure the jci profile is being activated? if another profile is specified for the build, the <activeByDefault> property won't enable the profile, see this bug for details.

From John Casey's response:

The above example is working as designed. The <activeByDefault/> element is meant to specify that this profile will be activated if no other profiles are active in the build. Therefore, specific activation of any profile will cause this one to be deactivated.

Psychophysics answered 27/7, 2009 at 0:23 Comment(3)
THanks for the answer. I'll look into run-exploded. And yes, I'm sure that the profile is active, that's not the problem.Stamin
mvn jetty:run-exploded -Dmaven.test.skip=true is a winner. Thanks!Stamin
Sorry, spoke to soon. Neither jsp changes nor javarebel class reloading seem to take effect.Stamin
S
1

The filtered files usually end up in the build target-directory. If you run 'mvn jetty:run' it uses per default your unfiltered src/main/webapp directory. All you got to do is to add the build-target as additional resource directory. Done so, jetty will create an overlay and will also use the filtered files.

                <plugin>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>maven-jetty-plugin</artifactId>
                    <version>6.1.26</version>
                    <configuration>
                        <webAppConfig>
                            <contextPath>/${project.build.finalName}</contextPath>
                            <baseResource implementation="org.mortbay.resource.ResourceCollection">
                                <resourcesAsCSV>src/main/webapp,${project.build.directory}/${project.build.finalName}</resourcesAsCSV>
                            </baseResource>
                        </webAppConfig>
                        <scanIntervalSeconds>2</scanIntervalSeconds>
                    </configuration>
                </plugin>
Sherfield answered 17/12, 2013 at 9:29 Comment(0)
E
0

Thanks to @Randy I managed to get this working too. Heres an up to date example showing both the resources filtering and the jetty rebasing baseResource using org.eclipse.jetty rather than the older mortbay. Here we are filtering two jsp pages login.jsp and index.jsp and setting a variable "${login.resources}" in the jsp to "login.res.jsp" as per the properties section below. Note we filter and write these to "jetty.docroot", then we overlay jetty.docroot over src/main/webapps so our filtered jsps get used by jetty. The overlay is updated from @Randy to use the newer "org.eclipse.jetty.util.resource.ResourceCollection" implementation.

<profiles>
<profile>
    <id>jetty</id>

    <properties>
        <jetty.docroot>${project.build.directory}/jetty</jetty.docroot>
        <login.resources>login.res.jsp</login.resources>
    </properties>

    <build>

        <plugins>

            <plugin>
                <artifactId>maven-resources-plugin</artifactId>
                <version>3.0.2</version>
                <executions>
                    <execution>
                        <id>jetty-docroot</id>
                        <!-- test-compile precedes jetty:run -->
                        <phase>test-compile</phase>

                        <goals>
                            <goal>copy-resources</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${jetty.docroot}</outputDirectory>
                            <resources>
                                <resource>
                                    <directory>${basedir}/src/main/webapp</directory>
                                    <filtering>true</filtering>
                                    <includes>
                                        <include>**/login.jsp</include>
                                        <include>**/index.jsp</include>
                                    </includes>
                                </resource>
                            </resources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

            <plugin>

                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.4.0.v20161208</version>
                <configuration>

                    <scanIntervalSeconds>2</scanIntervalSeconds>

                    <webApp>
                        <contextPath>/intamerge</contextPath>
                         <baseResource implementation="org.eclipse.jetty.util.resource.ResourceCollection">

                             <resourcesAsCSV>${jetty.docroot},${basedir}/src/main/webapp</resourcesAsCSV>
                            </baseResource>
                        <baseAppFirst>false</baseAppFirst>
                    </webApp>


                </configuration>
            </plugin>
        </plugins>
    </build>
</profile>

Electrotherapeutics answered 14/2, 2017 at 10:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.