如何保持maven原型文件的可执行权限

bar*_*ber 5 maven maven-archetype

我正在构建一个原型,我想在其中包含一个带有一些可执行二进制文件的文件夹.问题是,当我从原型创建一个新项目时,创建的可执行二进制文件没有可执行权限.

如何告诉maven保留对这些文件的执行权限?或者也许有一种方法告诉maven在生成时自动添加执行权限?

Fer*_*zyn 6

这个问题已经很老了,但是我发现自己处在相同的情况下,并且找到了解决方案,所以就去了。在这里它说,你可以写一个Groovy脚本命名为原型,后generate.groovy新的项目产生后在src /主/资源/ META-INF /你的原型的文件夹,以便进行操作。该脚本应如下所示:

def file = new File( request.getOutputDirectory(), request.getArtifactId()+"RELATIVE_PATH" );
file.setExecutable(true, false);
Run Code Online (Sandbox Code Playgroud)

其中request.getOutputDirectory()是将在其中创建新项目的目录,而request.getArtifactId()是项目工件ID。


abe*_*res 1

我使用 exec-maven-plugin 解决了类似的问题,执行了两次,一次是压缩目录,另一次使用 bin 分类器部署到存储库(在我的情况下)到第三方。所以我将所有unix权限保存在zip文件中。

<plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>exec-maven-plugin</artifactId>
    <version>1.2.1</version>
    <executions>
        <execution>
            <id>1</id>
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>zip</executable>
                <workingDirectory>${basedir}</workingDirectory>
                <arguments>
                    <argument>-r</argument>
                    <argument>target/com.example.test.ext.zip</argument>
                    <argument>Out</argument>
                    <argument>-x</argument>
                    <argument>*.svn*</argument>
                </arguments>
            </configuration>
        </execution>
        <execution>
            <id>2</id>
            <phase>package</phase>
            <goals>
                <goal>exec</goal>
            </goals>
            <configuration>
                <executable>mvn</executable>
                <workingDirectory>${basedir}/target</workingDirectory>
                <arguments>
                    <argument>deploy:deploy-file</argument>
                    <argument>-Dfile=com.example.test.ext.zip</argument>
                    <argument>-Dclassifier=bin</argument>
                    <argument>-DgroupId=com.example</argument>
                    <argument>-DartifactId=test</argument>
                    <argument>-Dversion=1.0</argument>
                    <argument>-Dpackaging=zip</argument>
                    <argument>-DrepositoryId=releases</argument>
                    <argument>-Durl=http://nexus..../nexus/content/repositories/thirdparty
                    </argument>
                </arguments>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)

如果您使用结果作为依赖项,请不要忘记“bin”分类器:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <version>2.8</version>
    <executions>
        <execution>
            <id>unpack1</id>
            <phase>generate-resources</phase>
            <goals>
                <goal>unpack</goal>
            </goals>
            <configuration>
                <artifactItems>
                    <artifactItem>
                        <groupId>com.example</groupId>
                        <artifactId>test</artifactId>
                        <version>1.0-SNAPSHOT</version>
                        <classifier>bin</classifier>
                        <type>zip</type>
                        <overWrite>true</overWrite>
                        <outputDirectory>output</outputDirectory>
                    </artifactItem>
                </artifactItems>
            </configuration>
        </execution>
    </executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)