我正在構建一個原型,我想在其中包含一些帶有一些可執行二進制文件的文件夾。問題是,當我從原型創建一個新項目時,創建的可執行二進制文件沒有可執行權限。如何保持對maven原型文件的可執行權限
我該如何告訴maven保持這些文件的執行權限?或者也許有一種意思是告訴Maven在生成時自動添加執行權限?
我正在構建一個原型,我想在其中包含一些帶有一些可執行二進制文件的文件夾。問題是,當我從原型創建一個新項目時,創建的可執行二進制文件沒有可執行權限。如何保持對maven原型文件的可執行權限
我該如何告訴maven保持這些文件的執行權限?或者也許有一種意思是告訴Maven在生成時自動添加執行權限?
我用兩次執行解決了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>
看到這個職位的另一個例子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安裝而不僅僅是原型生成,所以如果任何人有任何更好的建議,然後會喜歡聽到他們。
這個問題已經很老了,但是我發現自己處於同樣的狀況,我發現了一個解決方案,所以就這樣了。 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的目錄。
此外,由於您需要考慮Windows,添加配置文件等,因此會變得更加混亂 – 2014-06-20 15:29:44