2017-01-14 13 views
1

プロジェクトルートのdist/のように、いくつかのディレクトリ(jar、起動スクリプト、ドキュメント)にいくつかのファイルをコピーしたいとします。Maven、ファイルのコピー方法は?

私はmaven-assembly-pluginを使用し、<configuration><outputDirectory>をpom.xmlに設定しています。ファイルはdist/ですが、<my_project>-<decsriptor_id>/サブディレクトリに作成されます。

dist/のルートに出力する方法はありますか?

Mavenにファイルを単にコピーするプラグインがありますか?

 <plugin> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>3.0.0</version> 
      <executions> 
       <execution> 
        <id>maven-assembly</id> 
        <phase>package</phase> 
        <goals> 
         <goal>single</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <outputDirectory>${project.basedir}/dist</outputDirectory> 
       <descriptors> 
        <descriptor>${project.basedir}/src/main/maven-assembly/dist.xml</descriptor> 
       </descriptors> 
      </configuration> 
     </plugin> 

dist.xml

<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0" 
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
      xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd"> 
    <id>dist</id> 
    <formats> 
     <format>dir</format> 
    </formats> 
    <includeBaseDirectory>false</includeBaseDirectory> 
    <files> 
     <file> 
      <source>path........</source> 
      <fileMode>0755</fileMode> 
      <outputDirectory>.</outputDirectory> 
     </file> 
    </files> 
</assembly> 
+1

あなたは '' DIRでディレクトリを作成するプラグインを告げたので、なぜあなたは持っていることに驚いていますそれは出力? ZIPを作成し、( ' false'のために)ここには基本ディレクトリがないことを確認してください。あなたが達成しようとしている仕事は何ですか?また、 'target'以外の場所にファイルを作成しないでください(' $ {project.basedir}/dist 'は良い考えではありません)。 – Tunaki

+0

便宜のために、1つのディレクトリにすべての必要なファイルを(異なる場所から)、ターゲットから他のものをすべて持たないようにしてください。なぜそれは良い考えではないのですか? – AlexP11223

+0

srcフォルダがバージョン管理下にあるため、ビルド中に生成されたファイルで汚染されていることを意味します...デフォルトでは、ターゲットフォルダは除外する必要があります(コンパイルされたクラス、コンパイルテストなど、作成されたzipファイルまたはjarファイル)....これは良い考えではない理由です... – khmarbaise

答えて

1

あなたはmaven-resources-pluginを使用することがあります。

<plugin> 
    <artifactId>maven-resources-plugin</artifactId> 
    <version>3.0.2</version> 
    <executions> 
    <execution> 
    <id>copy-resources</id> 
    <!-- here the phase you need --> 
    <phase>validate</phase> 
    <goals> 
     <goal>copy-resources</goal> 
    </goals> 
    <configuration> 
     <outputDirectory>${basedir}/target/extra-resources</outputDirectory> 
     <resources>   
     <resource> 
     <directory>src/non-packaged-resources</directory> 
     <filtering>true</filtering> 
     </resource> 
     </resources>   
    </configuration>   
    </execution> 
    </executions> 
</plugin> 
関連する問題