2013-03-07 42 views
5

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

我该如何告诉maven保持这些文件的执行权限?或者也许有一种意思是告诉Maven在生成时自动添加执行权限?

回答

1

我用两次执行解决了exec-maven-plugin的类似问题,其中一个是zip导引器,另一个是使用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> 

如果使用结果作为depenency不要忘记的“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> 
0

看到这个职位的另一个例子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> 

但是,这似乎是浪费运行此eac h安装而不仅仅是原型生成,所以如果任何人有任何更好的建议,然后会喜欢听到他们。

+0

此外,由于您需要考虑Windows,添加配置文件等,因此会变得更加混乱 – 2014-06-20 15:29:44

1

这个问题已经很老了,但是我发现自己处于同样的状况,我发现了一个解决方案,所以就这样了。 Here它表示您可以在原型的src/main/resources/META-INF /文件夹中编写一个名为的常规脚本archetype-post-generate.groovy,以便在新项目生成后执行操作。该脚本应该是这样的一个:

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

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

相关问题