Use Maven assembly plugin to set Linux file permissions even when run on other platforms?

余生长醉 提交于 2019-12-03 16:23:29

问题


Similar question: Can Ant's tar task set a Linux file permission even when the task is used on other platforms?

If I use Maven 2 assembly plugin with the 'project' descriptor, is there a way to set shell script permissions to executable for example for included build.sh script files?

Example:

        <plugin>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.2</version>
            <configuration>
                <descriptorRefs>
                    <descriptorRef>project</descriptorRef>
                </descriptorRefs>
            </configuration>
        </plugin>

This will create three files

  • -project.tar.bz2
  • -project.tar.gz
  • -project-zip

And I would like to set the file permissions for all *.sh files which are in the tar files to 'executable'.


回答1:


This can be done using the fileMode parameter available in Maven Assembly Plugin assembly descriptor. For instance

<assembly>
    ...
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/bin</directory>
            <outputDirectory>/bin</outputDirectory>
            <includes>
                <include>*.sh</include>
            </includes>
            <fileMode>0755</fileMode>
        </fileSet>
        ...
    </fileSets>
    ...
</assembly>



回答2:


It was asked in comments how to set permisions for directories, so that they don't end up with d--------- permissions. The answer is pretty straightforward - use directoryMode:

<assembly>
    ...
    <fileSets>
        <fileSet>
            <directory>${project.build.directory}/bin</directory>
            <outputDirectory>/bin</outputDirectory>
            <includes>
                <include>*.sh</include>
            </includes>
            <fileMode>0755</fileMode>
            <directoryMode>0755</directoryMode>
        </fileSet>
        ...
    </fileSets>
    ...
</assembly>


来源:https://stackoverflow.com/questions/4719408/use-maven-assembly-plugin-to-set-linux-file-permissions-even-when-run-on-other-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!