如何在 Maven 输出中设置目录权限?
我正在使用 maven- assembly-plugin 来打包我的构建。
我可以执行一些文件集复制并很好地修改文件权限,但无法修改目录权限。从文档中,我尝试在我关心的目录上使用。但是,无论我指定什么权限,目录总是基于当前的 umask (0022) 创建。 有谁知道在 Maven 构建期间以这种方式修改目录权限的干净方法。唯一有效的是umask 0
,但我不想被迫这样做,因为从事该项目的每个人都必须拥有这套。
示例 maven assembly.xml:
<?xml version="1.0"?>
<assembly>
<id>zip-with-dependencies</id>
<formats>
<format>dir</format>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<dependencySets>
<dependencySet>
<includes>
<include>foo:bar</include>
</includes>
<outputDirectory>/resources/blah</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${basedir}/src/main/web</directory>
<includes>
<include>some_dir</include>
</includes>
<outputDirectory>web</outputDirectory>
<fileMode>0777</fileMode>
<directoryMode>0777</directoryMode>
</fileSet>
</fileSets>
</assembly>
I am using the maven-assembly-plugin to package my build.
I am able to perform some copying of file sets and modify file permissions fine, but I am unable to modify directory permissions. From the documentation, I am trying to use on the directories I care about. However, regardless of what permissions I specify, directories are ALWAYS created based off of the current umask (0022).
Does anyone know of a clean way to modify directory permissions in this way during a Maven build. The only thing that works is umask 0
, but I would rather not be forced to do this, since everyone working on this project would have to have this set.
Example maven assembly.xml:
<?xml version="1.0"?>
<assembly>
<id>zip-with-dependencies</id>
<formats>
<format>dir</format>
<format>tar.gz</format>
</formats>
<includeBaseDirectory>true</includeBaseDirectory>
<dependencySets>
<dependencySet>
<includes>
<include>foo:bar</include>
</includes>
<outputDirectory>/resources/blah</outputDirectory>
<useProjectArtifact>true</useProjectArtifact>
<unpack>true</unpack>
<scope>runtime</scope>
</dependencySet>
</dependencySets>
<fileSets>
<fileSet>
<directory>${basedir}/src/main/web</directory>
<includes>
<include>some_dir</include>
</includes>
<outputDirectory>web</outputDirectory>
<fileMode>0777</fileMode>
<directoryMode>0777</directoryMode>
</fileSet>
</fileSets>
</assembly>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也有同样的问题。我测试了上述所有解决方案,但没有一个对我有用。
我想到的对我有用的最佳解决方案是在实际写入这些父文件夹之前将其预先创建为空文件夹。
因此,为了解决原始问题,您应该使用:
这应该放在示例中资源子文件夹的实际副本之前。
./ - 只是一些现有的文件夹。它可以是任何其他文件夹,只要它存在即可。请注意,我们从文件集中排除任何文件。
因此,结果将是一个具有适当权限集的空文件夹。
附带说明一下,无论谁使用 tar 来打包文件,如果没有进行此设置,tar 文件都不会具有为此父文件夹设置的权限。因此,提取将产生一个新文件夹,但具有提取用户及其 umask 的权限。
当然,0700 只是为了示例而使用的。
I had the same problem. I tested all the above solutions and none of them worked for me.
The best solution I had in mind and that worked for me was to pre create these parent folders as empty folders, before actually writing to them.
So, to relate to the original problem, you should use:
This should be put before the actual copy to the subfolder of resources in your example.
./ - is simply some existing folder. It can be any other folder, as long as it exists. Note that we exclude any file from the fileSet.
So the result would be an empty folder with the appropriate set of permissions.
On a side note, whoever uses tar to pack the files, without this set, the tar file won't have the permissions set for this parent folder. So extraction will result with a new folder, but with permissions of the extracting user + his umask.
0700 was used only for the sake of the example, of course.
我通过结合 pom.xml 和程序集描述符中的设置解决了这个问题。
在 pom 中指定整个 zip 文件的默认值。
然后,在程序集描述符中,我为不应具有默认权限的各个文件夹提供覆盖。
这里,
bin
目录中的文件将为所有用户赋予可执行状态。conf
目录及其中的文件只有所有者才能访问,而db
目录继承了 pom.xml 中设置的权限。程序集文件设置在 http://maven.apache.org/ 中描述plugins/maven- assembly-plugin/ assembly.html
除了 amra 识别的 JIRA 问题之外,我找不到任何有关配置部分的官方文档。
I've solved this problem with a combination of settings in the pom.xml and the assembly descriptor.
In pom specify the defaults for the entire zip file.
Then in the assembly descriptor I provide the overrides for individual folders that shouldn't have the default permissions.
Here the files in the
bin
directory will be given executable state for all users. Theconf
directory and files in it are accessible only by the owner, and thedb
directory inherits the permissions from the settings in the pom.The assembly file settings are described at http://maven.apache.org/plugins/maven-assembly-plugin/assembly.html
I couldn't find any official documentation on the configuration section other than the JIRA issue that amra identified.
我发现JIRA问题描述了这种行为。解决方法应该是
I found a JIRA issue describing this behavior. A workaround should be