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

3

7

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

Fleshy answered 3/11, 2011 at 11:26 Comment(4)
Shouldn't maven be putting it in WEB-INF/classes by default? This is where non-JAR resources need to go on the classpathSofa
@mattb you're correct, that's the way it should be, but in new-relics docs they say both files have to be in the same dircetory link to the docsFleshy
that seems odd. It would be unusual for a class to look for resources specifically in WEB-INF/lib rather than to just load it from the classpathSofa
@mattb I think it's because this jar is used for instrumentation ( -javaagent=newrelic.jar ) and I'm using Amazon elastic beanstalk so I have to package and deploy this monitoring war by myself.Fleshy
T
13

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.

Tug answered 3/11, 2011 at 13:16 Comment(0)
I
4

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.)

Intimist answered 31/7, 2012 at 17:28 Comment(0)
S
0
  1. You should try adding .yaml file to newrelic.jar's resources, later you can access it via classpath.
  2. Or try changing/overriding build.xml build target by adding something like < copy file=".yaml" todir="WEB-INF/lib" />

Try googling for more info on changing build.xml.

Several answered 3/11, 2011 at 12:14 Comment(1)
I'm not in control of newrelic.jar, it's a third-party. They look for the configuration file .yml in the same directory where the jar is. Another thing, I'm using Maven so there is not build.xml for me.Fleshy

© 2022 - 2024 — McMap. All rights reserved.