java 使 Maven 复制构建 jar 中的其他文件(不是资源,而是任何包中的任何文件)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10393404/
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
Making maven copy additional files inside the build jar (not resources but any file inside any package)?
提问by chrisapotek
I have a package org.myapp.mypackage
with some ruby files (*.rb
) and I need to include them in the generated build jar in the same packagealong with the java class files.
我有一个org.myapp.mypackage
包含一些 ruby 文件 ( *.rb
)的包,我需要将它们与 java 类文件一起包含在同一个包中生成的构建 jar中。
How do I tell my friend Maven to do this?
我如何告诉我的朋友 Maven 这样做?
Note : No, I cannot copy to anywhere else, but thanks for suggesting. :)
注意:不,我无法复制到其他任何地方,但感谢您的建议。:)
回答by artbristol
You can modify the resources section of the <build>
bit of the POM:
可以修改<build>
POM的bit的resources部分:
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>*.rb</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
Or, the other answer (create the same package structure in src/main/resources
) will also work.
或者,另一个答案(在 中创建相同的包结构src/main/resources
)也将起作用。
回答by J?rn Horstmann
Not sure if i understood the problem correctly, but if your Ruby files are packaged by maven and declared as a dependency, you can use the shade pluginto include the contents into the resulting jar file:
不确定我是否正确理解了问题,但是如果您的 Ruby 文件由 maven 打包并声明为依赖项,您可以使用shade 插件将内容包含到生成的 jar 文件中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<artifactSet>
<includes>
<include>org.myapp.mypackage:mypackage</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>org.myapp.mypackage:mypackage</artifact>
<includes>
<include>org/my/package/*.rb</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
回答by kunal
Put them in the correct directory (src/main/resources in general) and they should be bundled into the Jar properly. To put you *.rb files create the same dir structure under the src/main/resources folder.
将它们放在正确的目录中(一般是 src/main/resources),它们应该正确地捆绑到 Jar 中。为了让你 *.rb 文件在 src/main/resources 文件夹下创建相同的目录结构。