java 您如何创建一个包含不在 jar 中的 shell 脚本和属性文件的 Maven 程序集?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11631682/
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 do you create a maven assembly that includes shell scripts and properrties file not in jar?
提问by Paul Taylor
Im trying to use Maven to build a standalone application
我正在尝试使用 Maven 构建一个独立的应用程序
Using the assembly plugin described at How do you create a standalone application with dependencies intact using Maven?
使用在如何使用 Maven 创建具有完整依赖项的独立应用程序中描述的程序集插件 ?
This creates widget distribution zip containing
这将创建小部件分发 zip 包含
widget-1.0
widget-1.0/lib/widget.jar
widget-1.0/lib/3rdpartyjar1.jar
widget-1.0/lib/3rdpartyjar2.jar
...
...
but in my src tree I have:
但在我的 src 树中,我有:
src/main/bin/widget.sh
and this doesnt make into the final distribution zip, I would like it to go here
这不会成为最终的发行版 zip,我希望它放在这里
widget-1.0/widget.sh
Also in my src tree i have a properties file in
同样在我的 src 树中,我有一个属性文件
src/main/properties/widget.properties
that currently make its way into
目前进入
widget-1.0/lib/widget.jar
but because I want it to be editable I want it to be in
但因为我希望它是可编辑的,所以我希望它在
widget-1.0/widget.properties
Is it possible to do this within maven ?
可以在 maven 中做到这一点吗?
EDITUsing information in blog got working as follows:
编辑使用博客中的信息工作如下:
- Renamed bin folder to scripts folder because this is standard Maven name
- Moved widget.properties into script folder
- Modifed my assembly.xml to contain a fileset
- 将 bin 文件夹重命名为 scripts 文件夹,因为这是标准的 Maven 名称
- 将 widget.properties 移动到脚本文件夹中
- 修改我的 assembly.xml 以包含文件集
Here is the new xml
这是新的 xml
<?xml version="1.0" encoding="UTF-8"?>
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>distribution</id>
<formats>
<format>zip</format>
</formats>
<dependencySets>
<dependencySet>
<scope>runtime</scope>
<outputDirectory>lib</outputDirectory>
<unpack>false</unpack>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${project.build.scriptSourceDirectory}</directory>
<outputDirectory></outputDirectory>
<includes>
<include>widget.sh</include>
<include>widget.properties</include>
</includes>
</fileSet>
</fileSets>
</assembly>
However minor point but unable to find a list of maven standard folder variables anywhere , i.e is there an equivalent to ${project.build.scriptSourceDirectory} for the properties folder
然而,小点却无法在任何地方找到 maven 标准文件夹变量的列表,即是否有等效于 ${project.build.scriptSourceDirectory} 的属性文件夹
回答by jqno
I found this blog postto be a good tutorial on how to do this.
我发现这篇博文是关于如何做到这一点的一个很好的教程。
Also, I think the name of the folder in which you place your files is relevant. Maven obviously does different things with files in src/main/java
than with files in src/main/resources
. I'm not 100% sure, but the name of this folder might mean the difference between a file ending up inside the jar or not.
另外,我认为您放置文件的文件夹的名称是相关的。Maven的显然是与文件不同的东西src/main/java
比在文件中src/main/resources
。我不是 100% 确定,但这个文件夹的名称可能意味着文件在 jar 内与否之间的区别。
Hereis a list of Maven directory name properties.
这是 Maven 目录名称属性的列表。