java 如何让Maven复制资源文件到WEB-INF/lib目录下?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7994088/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make Maven copy resource file into WEB-INF/lib directory?
提问by AlexV
I'm using NewRelic for monitoring. I want Maven to package both newrelic.jarand newrelic.yamlfiles into my WEB-INF/lib
inside the war file. With the newrelic.jarthere is no problem since it's a simple dependency, but newrelic.yamlis a resource file. It resides in resources directory. I want Maven (war plugin) to copy it to WEB-INF/lib
when packaging the war.
我正在使用 NewRelic 进行监控。我希望 Maven 将newrelic.jar和newrelic.yaml文件打包到我WEB-INF/lib
的 war 文件中。使用newrelic.jar没有问题,因为它是一个简单的依赖项,但newrelic.yaml是一个资源文件。它驻留在资源目录中。我希望Maven(War插件)WEB-INF/lib
在打包War时将其复制到。
Thanks.
谢谢。
Alex
亚历克斯
回答by Chris
While I agree with @matt b that this is odd, here's what you can do:
虽然我同意@matt b 这很奇怪,但您可以这样做:
Try changing the configuration of the maven war plugin to include a webResource:
尝试更改 Maven War插件的配置以包含 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 documentationfor more info.
该目录是相对于 pom.xml 的。有关更多信息,请参阅插件的文档。
回答by fool
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:
您还可以通过传递给 java 命令的标志为 New Relic 代理指定大多数配置,包括配置文件的位置。在这种情况下,它类似于:
-Dnewrelic.config.file=/etc/newrelic.yml
-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.)
(好吧,它正是那样,但如果不是那样,你需要指定你需要的任何路径。)
回答by JMelnik
- You should try adding .yaml file to newrelic.jar's resources, later you can access it via classpath.
- Or try changing/overriding build.xml build target by adding something like < copy file=".yaml" todir="WEB-INF/lib" />
- 您应该尝试将 .yaml 文件添加到 newrelic.jar 的资源中,稍后您可以通过类路径访问它。
- 或者尝试通过添加类似 <copy file=".yaml" todir="WEB-INF/lib" /> 的内容来更改/覆盖 build.xml 构建目标
Try googling for more info on changing build.xml.
尝试使用谷歌搜索有关更改 build.xml 的更多信息。