Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在maven原型中保留文件的可执行权限_Maven_Maven Archetype - Fatal编程技术网

如何在maven原型中保留文件的可执行权限

如何在maven原型中保留文件的可执行权限,maven,maven-archetype,Maven,Maven Archetype,我正在构建一个原型,我想在其中包含一个包含一些可执行二进制文件的文件夹。问题是,当我从原型创建新项目时,可执行二进制文件是在没有可执行权限的情况下创建的 我如何告诉maven保留对这些文件的执行权限?或者,也许有一种方法可以告诉maven在生成时自动添加执行权限?我用exec maven插件解决了类似的isue问题,执行了两次,一次是压缩目录,另一次是使用bin分类器部署到存储库,在我的例子中是部署到第三方。因此,我将所有unix权限保存在zip文件中 <plugin> &l

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


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

我用exec maven插件解决了类似的isue问题,执行了两次,一次是压缩目录,另一次是使用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>

org.codehaus.mojo
execmaven插件
1.2.1
1.
包裹
执行官
拉链
${basedir}
-r
target/com.example.test.ext.zip
出来
-x
*.svn*
2.
包裹
执行官
mvn
${basedir}/目标
部署:部署文件
-Dfile=com.example.test.ext.zip
-dclassizer=bin
-DgroupId=com.example
-DartifactId=测试
-Dversion=1.0
-dpackage=zip
-DrepositoryId=释放
-杜尔=http://nexus..../nexus/content/repositories/thirdparty
如果将结果用作依赖项,请不要忘记“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>

org.apache.maven.plugins
maven依赖插件
2.8
解开
产生资源
打开
com.example
测试
1.0-快照
箱子
拉链
真的
输出

另一个例子见本文

因此,我通过添加以下内容来解决这个问题:

            <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <id>script-chmod</id>
                    <phase>install</phase>
                    <goals>
                        <goal>exec</goal>
                    </goals>
                    <configuration>
                        <executable>chmod</executable>
                        <arguments>
                            <argument>+x</argument>
                            <argument>myscript</argument>
                        </arguments>
                    </configuration>
                </execution>
            </executions>
        </plugin>

org.codehaus.mojo
execmaven插件
1.2.1
脚本chmod
安装
执行官
奇莫德
+x
myscript

但是,在每次安装时运行此选项似乎是浪费时间,而不仅仅是在原型生成时运行此选项,因此如果有人有更好的建议,那么很乐意听取他们的建议。

这个问题很老了,但我发现自己也遇到了同样的情况,我找到了一个解决方案,就这样。它说,您可以在原型的src/main/resources/META-INF/文件夹中编写名为archetype post generate.groovy的groovy脚本,以便在生成新项目后执行操作。脚本应如下所示:

def file = new File( request.getOutputDirectory(), request.getArtifactId()+"RELATIVE_PATH" );
file.setExecutable(true, false);

<> > <强>请求.GETOutPuttoDirectory()/StUr>是创建新项目的目录,并且<强>请求.GETARTAFACTIONTIOR()/Projt是项目工件ID。

这也变得更加混乱,因为您需要考虑窗口、添加配置文件等。