2011-01-05 9 views
6

Sử dụng maven-lắp ráp-pluginMaven. Làm thế nào để bao gồm thư mục cụ thể hoặc tập tin khi lắp ráp dự án tùy thuộc vào nó là dev xây dựng hoặc sản xuất?

<plugin> 
<artifactId>maven-assembly-plugin</artifactId> 
<version>2.1</version> 
<configuration> 
<descriptors> 
    <descriptor>descriptor.xml</descriptor> 
</descriptors> 
<finalName>xxx-impl-${pom.version}</finalName> 
<outputDirectory>target/assembly</outputDirectory> 
<workDirectory>target/assembly/work</workDirectory> 
</configuration> 

trong tập tin descriptor.xml chúng ta có thể xác định

<fileSets> 
    <fileSet> 
     <directory>src/install</directory> 
     <outputDirectory>/</outputDirectory> 
    </fileSet> 
</fileSets> 

Có thể bao gồm tập tin cụ thể từ các thư mục này hoặc thư mục con tùy thuộc vào Hồ sơ? Hoặc một số cách khác ...

Như thế này:

<profiles> 
    <profile> 
     <id>dev</id> 
     <activation> 
      <activeByDefault>false</activeByDefault> 
     </activation> 
     <build> 
      <resources> 
       <resource> 
        <directory>src/install/dev</directory> 
        <includes> 
         <include>**/*</include> 
        </includes> 
       </resource> 
      </resources> 
     </build> 
    </profile> 
    <profile> 
     <id>prod</id> 
     <build> 
      <resources> 
       <resource> 
        <directory>src/install/prod</directory> 
        <includes> 
         <include>**/*</include> 
        </includes> 
       </resource> 
      </resources> 
     </build> 
    </profile> 
</profiles> 

Nhưng nó đặt nguồn lực trong jar khi đóng gói. Nhưng chúng ta cần phải đặt nó trong zip khi lắp ráp như tôi đã đề cập ở trên :( Cảm ơn

Trả lời

12

Nếu nguồn của bạn có một mô hình (nói *.properties) sau đó bạn có thể làm một cái gì đó như thế này trong tập tin mô tả assembly của bạn:

<fileSets> 
     <fileSet> 
      <directory>${project.build.directory}</directory> 
      <outputDirectory>/</outputDirectory> 
      <includes> 
       <include>*.properties</include> 
      </includes> 
     </fileSet> 
</fileSets> 
bản

này tất cả *.properties từ thư mục target của bạn vào thư mục gốc của zip lắp ráp của mình. Dựa trên tiểu sử được pom.xml của bạn đó là được chạy, chỉ có nguồn lực phù hợp sẽ có mặt trong thư mục target.

+0

Cảm ơn !!!!!!!!!!!!!!! – whatswrong

2

Đặt các thực thi của plugin trong mỗi cấu hình, bên trong xây dựng thẻ.

<build> 
    <plugins> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-dependency-plugin</artifactId> 
     <executions> 
      <execution> 
      <phase>grr</phase> 
      <goals> 
       <goal>tree</goal> 
      </goals> 
      </execution> 
     </executions> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-jar-plugin</artifactId> 
     <version>2.3.1</version> 
     <configuration> 
      <excludes> 
      <exclude>**/*.xml</exclude> 
      </excludes> 
     </configuration> 
     </plugin> 

    </plugins> 
    </build> 
    <profiles> 
    <profile> 
     <id>dev</id> 
     <activation> 
     <activeByDefault>false</activeByDefault> 
     </activation> 
     <build> 
     <plugins> 
      <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.1</version> 
      <configuration> 
       <descriptors> 
       <descriptor>descriptor.xml</descriptor> 
       </descriptors> 
       <finalName>xxx-impl-${pom.version}</finalName> 
       <outputDirectory>target/assembly</outputDirectory> 
       <workDirectory>target/assembly/work</workDirectory> 
      </configuration> 
      </plugin> 
      <resources> 
      <resource> 
       <directory>src/install/dev</directory> 
       <includes> 
       <include>**/*</include> 
       </includes> 
      </resource> 
      </resources> 
     </build> 
    </profile> 
    <profile> 
     <id>prod</id> 
     <build> 
     <resources> 
      <resource> 
      <directory>src/install/prod</directory> 
      <includes> 
       <include>**/*</include> 
      </includes> 
      </resource> 
     </resources> 
     </build> 
    </profile> 
    </profiles>