Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Maven copy resource file into WEB-INF/lib directory?

I'm using NewRelic for monitoring. I want Maven to package both newrelic.jar and newrelic.yaml files into my WEB-INF/lib inside the war file. With the newrelic.jar there is no problem since it's a simple dependency, but newrelic.yaml is a resource file. It resides in resources directory. I want Maven (war plugin) to copy it to WEB-INF/lib when packaging the war.

Thanks.

Alex

like image 292
AlexV Avatar asked Nov 03 '11 11:11

AlexV


People also ask

Where does Web XML go in Maven project?

web. xml file is always inside WEB-INF folder, by default Maven is expecting it in there and its the first location that is being searched for a web.

What is packagingExcludes?

packagingExcludes: The comma separated list of tokens to exclude from the WAR before packaging. With packagingExcludes, the tokens are completely excluded from the final war file. With warSourceExcludes, the tokens are just ignored when copying the war directory into the war file.

Which file extensions are excluded for resource filtering by default in Maven?

The plugin will prevent binary files filtering without adding some excludes configuration for the following file extensions jpg , jpeg , gif , bmp and png . If you like to add supplemental file extensions this can simply achieved by using a configuration like the following: <project>

What is the use of Maven war plugin?

The WAR Plugin is responsible for collecting all artifact dependencies, classes and resources of the web application and packaging them into a web application archive.


2 Answers

While I agree with @matt b that this is odd, here's what you can do:

Try changing the configuration of the maven war plugin to include a webResource:

 <configuration>
      <webResources>
        <resource>
          <directory>pathtoyaml</directory>
          <includes>
            <include>**/*.yaml</include>
          <includes>        
         <targetPath>WEB-INF/lib</targetPath>
        </resource>
      </webResources>
    </configuration>

The directory is relative to the pom.xml. See the plugin's documentation for more info.

like image 148
Chris Avatar answered Sep 28 '22 19:09

Chris


You can also specify most configuration for the New Relic agent including the location of the config file via flags passed to the java command. In this case, it's something like:

-Dnewrelic.config.file=/etc/newrelic.yml

(ok, it's exactly like that, but you need to specify whatever path you need if it's not that.)

like image 35
fool Avatar answered Sep 28 '22 19:09

fool