2013-03-07 34 views
5

Tôi đang tạo một kiểu mẫu mà tôi muốn đưa vào một thư mục có một số tệp nhị phân thực thi. Vấn đề là khi tôi tạo một dự án mới từ nguyên mẫu, các tệp nhị phân thực thi được tạo mà không có quyền thực thi.Làm thế nào để giữ quyền thực thi trên các tệp trong một nguyên mẫu maven

Làm cách nào để tôi có thể yêu cầu maven giữ quyền thực thi trên các tệp đó? Hoặc có thể có nghĩa là để nói với maven để thêm quyền thực thi tự động tại thời gian thế hệ?

Trả lời

1

Tôi đã giải quyết isue tương tự bằng lệnh exec-maven-plugin với hai lần thực hiện, một là zip directorys và triển khai khác với bộ phân loại bin vào kho lưu trữ trong trường hợp của tôi cho bên thứ ba. Vì vậy, tôi đã lưu tất cả các quyền unix trong tệp 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> 

Nếu bạn sử dụng kết quả như một depenency không quên "bin" phân loại:

<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

Xem bài đăng này cho một ví dụ khác maven calls external script on both Linux and Windows platforms

Vì vậy, tôi đã làm việc tròn này bằng cách thêm những điều sau đây :

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

Tuy nhiên, điều này dường như lãng phí khi chạy điều này cho eac h cài đặt hơn là chỉ trên thế hệ nguyên mẫu vì vậy nếu có ai có bất kỳ đề xuất nào tốt hơn thì rất thích nghe chúng.

+0

Ngoài ra điều này trở nên lộn xộn hơn khi bạn cần phải xem xét cửa sổ, thêm hồ sơ v.v. –

1

Câu hỏi này khá cũ, nhưng tôi thấy mình trong tình huống tương tự và tôi đã tìm thấy một giải pháp, vì vậy ở đây nó đi. Here nó nói rằng bạn có thể viết một tập lệnh groovy có tên là archetype-post-generate.groovy trong thư mục src/main/resources/META-INF/của nguyên mẫu của bạn để thực hiện các hành động sau khi dự án mới được tạo. Các kịch bản sẽ giống như thế này:

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

nơi request.getOutputDirectory() là thư mục nơi mà các dự án mới sẽ được tạo ra và request.getArtifactId() là id tạo tác của dự án.

Các vấn đề liên quan