title: How to filter resources when using maven jetty plugin?
body: <p>I have an XML file (urlrewrite.xml) that needs a property placeholder resolved. I enable Maven filtering to achieve this. This works fine for the assembled WAR file.</p>
  
  <pre><code>&lt;build&gt;
      &lt;resources&gt;
          &lt;resource&gt;
              &lt;directory&gt;src/main/resources&lt;/directory&gt;
              &lt;filtering&gt;true&lt;/filtering&gt;
          &lt;/resource&gt;
  </code></pre>
  
  <p>The problem is when trying to run the application in development mode using the maven-jetty-plugin (Maven Jetty Plugin), as maven jetty:run .</p>
  
  <p>The file in question, urlrewrite.xml, is located in the src/main/resources directory, and therefore should (and does) ends up in /WEB-INF/classes (or target/classes for maven jetty:run).</p>
  
  <p>The URLRewriteFilter config specifies the location of the config file as follows:</p>
  
  <pre><code>&lt;filter&gt;
      &lt;filter-name&gt;UrlRewriteFilter&lt;/filter-name&gt;
      &lt;filter-class&gt;org.tuckey.web.filters.urlrewrite.UrlRewriteFilter&lt;/filter-class&gt;
      &lt;init-param&gt;
          &lt;param-name&gt;confPath&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/classes/urlrewrite.xml&lt;/param-value&gt;
      &lt;/init-param&gt;
  &lt;/filter&gt;
  </code></pre>
  
  <p>This will work at deployment time. However, Using the jetty maven plugin, URLRewrite will die with a NullPointerException because it uses context.getResourceAsString("/WEB-INF/classes/urlrewrite.xml") in order to load the config file. Jetty returns null for this because when running the application from workspace it resolves /WEB-INF/classes/... to src/main/webapp/WEB-INF/... . The file does not exist there because the WAR has not yet been assembled. It should instead pull the resource from target/classes/urlrewrite.xml.</p>
  
  <p>If that is obscure to you, then you probably won't be able to answer this question because I suspect you will need to be a Jetty guru to figure out a workaround (hint: that's a challenge!).</p>
  
  <p>Does anyone know a way around this? I have also tried the following workarounds to know avail:</p>
  
  <ol>
  <li>Put urlrewrite.xml under a new directory, src/main/webResources and add it to the maven war plugin &lt;webReources&gt; and enable filtering. That will copy it's contents in the appropriate location when the WAR is packaged, but will not make it available for jetty:run</li>
  <li>Some other hacks I can't even remember ... (will update if I do)</li>
  </ol>
  
  <p>In summary, maven-jetty-plugin needs the file to be under src/main/resources/webapp/<em>insert path and filename</em> in order to be available for the maven jetty:run command ...</p>
  
  <p>Thanks for you help ...</p>
  
  <p>Sincerely,
  Lloyd Force</p>