2016-06-25 4 views
1

Javaコードがいくつかのファイルを作成し、内部的にzipにコピーしようとしました。しかし、一部のファイルを除き、すべてのファイルがコピーされます。私はこれの背後にある理由を見つけることができません。生成されたファイルは、アセンブリプラグインを使用してMavenプロジェクトジップにコピーされません。

私は自分の許可でコピーしようとしたフォルダのディレクトリ構造と、それがターゲットフォルダ(zipファイル)にコピーされたものを追加します。 Mavenのプラグインを使用してzipファイルにすべてのこれらのファイルをコピーしようとすると

 

XYZ-MacBook-Pro:etl_configs XYZ$ pwd 
FILE_PATH_LOCATION/etl_configs 

XYZ-MacBook-Pro:etl_configs XYZ$ ls -l * 
-rw-r--r-- 1 XYZ staff 980 Jun 26 01:02 etl-spec.json 
-rwxr-xr-x 1 XYZ staff 2037 Jun 15 19:04 etl-without-transformation.json 

feeds: 
total 16 
-rw-r--r-- 1 XYZ staff 612 Jun 26 00:54 feed_1.json 
-rw-r--r-- 1 XYZ staff 616 Jun 26 01:02 feed_2.json 

tables: 
total 16 
-rw-r--r-- 1 XYZ staff 878 Jun 26 00:54 table_1.json 
-rw-r--r-- 1 XYZ staff 880 Jun 26 01:02 table_2.json 

-

のディレクトリ構造とその権限

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.5.5</version> 
    <configuration> 
     <descriptor>${project.basedir}/zip.xml</descriptor> 
    </configuration> 
    <executions> 
     <execution> 
      <id>make-assembly</id> 
      <phase>package</phase> 
      <goals> 
       <goal>single</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

zip.xmlファイルが含まれています -

<fileSet> 
     <directory>${project.basedir}/etl_configs</directory> 
     <outputDirectory>/etl_configs</outputDirectory> 
     <includes> 
       <include>*</include> 
     </includes> 
</fileSet> 

対象のzipファイルを理想的には、ジップの内側にフォルダ全体をコピーする必要があり

XYZ-MacBook-Pro:etl-without-transformation-template-1.0-SNAPSHOT XYZ$ pwd 
FILE_PATH_LOCATION/target/etl-without-transformation-template-1.0-SNAPSHOT-zip/etl-without-transformation-template-1.0-SNAPSHOT 
XYZ-MacBook-Pro:etl-without-transformation-template-1.0-SNAPSHOT XYZ$ ls -l etl_configs/* 
-rwxr-xr-x 1 XYZ staff 980 Jun 26 01:02 etl_configs/etl-spec.json 
-rwxr-xr-x 1 XYZ staff 2037 Jun 15 19:04 etl_configs/etl-without-transformation.json 

etl_configs/feeds: 

etl_configs/tables: 

をcontains-。しかし、それは起こっていません。

答えて

1

アセンブリディスクリプタ内に<includes>を使用する方法に関連する問題です。現在「etl_configsの下にすべてのファイルを含める」を意味する

<fileSet> 
    <directory>${project.basedir}/etl_configs</directory> 
    <outputDirectory>/etl_configs</outputDirectory> 
    <includes> 
     <include>*</include> 
    </includes> 
</fileSet> 

を使用しています。これは「すべてのファイルを再帰的にetl_configsに含めます」という意味ではありません。これは、maven-assembly-pluginがAntスタイルパターンを使用し、* matches zero or more characters within a path nameというAntではディレクトリ境界を超えていないため、<include>*</include>を使用しているためです。

<fileSet> 
    <directory>${project.basedir}/etl_configs</directory> 
    <outputDirectory>/etl_configs</outputDirectory> 
    <includes> 
     <include>**</include> 
    </includes> 
</fileSet> 

しかし、this is the default behaviour

<include>サブ要素が存在する場合、それらが含まれるファイルやディレクトリのセットを定義再帰的に使用することができるすべてのファイルを含めるためにこのよう

、 。存在しない場合、<includes>はすべての有効な値を表します。

だから、あなただけ持つことができます。

<fileSet> 
    <directory>${project.basedir}/etl_configs</directory> 
    <outputDirectory>/etl_configs</outputDirectory> 
</fileSet> 
+0

それは働きました。ありがとう。 – devsda

関連する問題