【问题标题】:How to keep executable permissions on files in a maven archetype如何在 Maven 原型中保留文件的可执行权限
【发布时间】:2013-02-22 19:03:13
【问题描述】:

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

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

【问题讨论】:

    标签: maven maven-archetype


    【解决方案1】:

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

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

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

    【讨论】:

      【解决方案2】:

      我用 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>
      

      如果您将结果用作依赖项,请不要忘记“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>
      

      【讨论】:

        【解决方案3】:

        有关另一个示例maven calls external script on both Linux and Windows platforms

        ,请参阅此帖子

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

                    <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>
        

        但是,对于每次安装而不是仅在原型生成上运行它似乎很浪费,所以如果有人有任何更好的建议,那么很想听听。

        【讨论】:

        • 此外,这会变得更加混乱,因为您需要考虑窗口、添加配置文件等
        猜你喜欢
        • 2022-01-15
        • 2011-11-02
        • 2018-08-08
        • 1970-01-01
        • 1970-01-01
        • 2012-01-10
        • 2017-04-24
        • 2023-03-04
        • 2020-10-12
        相关资源
        最近更新 更多