2013-12-23 7 views
9

私はMaven Assembly Pluginによって生成された最終出力ファイルの名前を変更する必要があるプロジェクトを持っています。Mavenは他のすべてが終了した後にファイルの名前を変更します

Maven Assembly Pluginは、プロジェクトの名前に基づいて最終的に.zipファイルを生成しています。この名前を完全にfinal-version.oxtに変更する必要があります。私はmaven-antrun-pluginを使用して名前を変更しようとしていますが、他の同様の質問で指摘されていますが運がありません(以前はMavenやAntを使用していませんでした。

これは、プロジェクトpom.xml<build>セクションです。私のhomeフォルダにファイルが生成されていないので、リネーム部分は完全に無視されているようです。

<build> 
    <plugins> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-assembly-plugin</artifactId> 
      <version>2.4</version> 
      <executions> 
       <execution> 
        <id>assembly</id> 
        <phase>package</phase> 
        <goals> 
         <goal>attached</goal> 
        </goals> 
        <configuration> 
         <archive> 
          <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> 
         </archive> 
         <descriptors> 
          <descriptor>src/main/assembly/ooo-jar.xml</descriptor> 
          <descriptor>src/main/assembly/ooo.xml</descriptor> 
         </descriptors> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <executions> 
       <execution> 
        <phase>deploy</phase> 

        <configuration> 
         <tasks> 
          <copy file="${project.build.directory}/target/libreofficeplugin-ooo.zip" 
          tofile="/home/brunofinger/final-version.oxt" /> 
         </tasks> 
        </configuration> 
       </execution> 
      </executions> 
     </plugin> 

    </plugins> 
</build> 

答えて

9

いくつかの変更は、おそらくphaseが間違っていた、それが仕事作ったが、<phase>install</phase>を使用すると、それを動作させるようだ:

<plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <version>1.7</version> 
      <executions> 
       <execution> 
        <phase>install</phase> 

        <configuration> 
         <target> 
          <copy file="${project.build.directory}/libreofficeplugin-ooo.zip" tofile="${project.build.directory}/final-version.oxt" /> 
         </target> 
        </configuration> 
        <goals> 
         <goal>run</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
-1

antrunを使用して出力ファイルの名前を変更する必要はありません。アセンブラプラグインのタグfinalNameを使用して、出力ファイルの名前を変更するだけです。

<?xml version="1.0" encoding="UTF-8"?> 
<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>2.4</version> 
    <executions> 
     <execution> 
     <id>assembly</id> 
     <phase>package</phase> 
     <goals> 
      <goal>attached</goal> 
     </goals> 
     <configuration> 
      <archive> 
       <manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> 
      </archive> 
      <descriptors> 
       <descriptor>src/main/assembly/ooo-jar.xml</descriptor> 
       <descriptor>src/main/assembly/ooo.xml</descriptor> 
      </descriptors> 
      <finalName>final-version.oxt</finalName> 
     </configuration> 
     </execution> 
    </executions> 
</plugin> 
+1

これはうまくいかず、ファイルの最後に '.zip'拡張子を付けて、' final-version.oxt.zip'という名前のファイルを生成しています。私は '.zip'を取り除く必要があります。 –

+1

あなたは正しいです。 finalNameは、拡張子ではなくファイルの名前のみを名前変更します。 –

+0

'finalName'設定要素は、もはやmaven-assembly-plugin 3.0.0に存在しません。 – Barett

6

この質問はほぼ歳ですが、場合には他の誰であります同じような問題に直面している場合は、別の解決方法があります。

あなたはそれをやってのよりmavenish方法を探している場合は、

<plugin> 
    <groupId>com.coderplus.maven.plugins</groupId> 
    <artifactId>copy-rename-maven-plugin</artifactId> 
    <version>1.0.1</version> 
    <executions> 
     <execution> 
     <id>rename-file</id> 
     <phase>install</phase> 
     <goals> 
      <goal>rename</goal> 
     </goals> 
     <configuration> 
      <sourceFile>${project.build.outputDirectory}/libreofficeplugin-ooo.zip</sourceFile> 
      <destinationFile>${project.build.outputDirectory}/final-version.oxt</destinationFile> 
     </configuration> 
     </execution> 
    </executions> 
    </plugin> 

を使用することができますし、場合にあなたが名前変更するのではなく、コピーしたい、ではなくrename目標のcopy目標を使用しています。

関連する問題