2013-02-18 73 views
0

使用Maven我想用自定義擴展名(.bar)創建存檔文件。我必須在其中包含一個類文件和一個XML文件。如何使用Maven插件創建存檔文件

我嘗試了下面,但無法完成它。

 <plugins> 

     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-antrun-plugin</artifactId> 
      <version>1.6</version> 
      <executions> 

       <execution> 
        <id>compile</id> 
        <phase>compile</phase> 
        <configuration> 
         <target> 
          <echo message="generating document workflow .bar file" /> 
          **I need to copy a .class file and an xml file then build the .bar file.**         

          <!-- Create a bar file. --> 
          <zip basedir="${project.build.outputDirectory}" destfile="${project.build.outputDirectory}/document-workflow.bar" /> 
         </target> 
        </configuration> 
       </execution> 

      </executions> 
     </plugin> 

請您指導我?

我有另一個要求。基本上,我想要複製到jar的類文件應該在根中,而不是在包結構中。

回答

0

希望這本書能解決你的問題:

<plugin> 
    <artifactId>maven-antrun-plugin</artifactId> 
    <version>1.7</version> 
    <executions> 
     <execution> 
      <id>bar</id> 
      <phase>package</phase> 
      <configuration> 
       <target> 
        <echo message="generating document workflow .bar file" /> 
        <!-- flatten files --> 
        <copy todir="${project.build.directory}/flattened_classes" flatten="true"> 
         <fileset dir="${project.build.outputDirectory}"> 
          <include name="**/*.class"/> 
         </fileset> 
        </copy> 
        <!-- Create a bar file. --> 
        <zip destfile="${project.build.directory}/document-workflow.bar" > 
         <fileset dir="${project.build.directory}/flattened_classes"> 
          <include name="**/*.class"/> 
         </fileset> 
         <fileset dir="${project.build.directory}"> 
          <include name="yourfile.xml"/> 
         </fileset> 
        </zip> 
       </target> 
      </configuration> 
      <goals> 
       <goal>run</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 
+0

優秀。非常感謝您的詳細代碼。 – user1659473 2013-02-21 13:32:48

相關問題