2017-03-08 13 views
1

我有一個Maven項目,它使用exec-maven-plugin來執行一個帶有main方法的類,並且這會在目標目錄中生成一個輸出文件。配置是這樣的:Maven:如何打包和部署由main()方法執行生成的輸出文件?

<plugin> 
    <groupId>org.codehaus.mojo</groupId> 
    <artifactId>exec-maven-plugin</artifactId> 
    <version>1.5.0</version> 
    <executions> 
     <execution> 
      <id>process-execution</id> 
      <phase>package</phase> 
      <goals> 
       <goal>java</goal> 
      </goals> 
     </execution> 
    </executions> 
    <configuration> 
     <mainClass>com.example.MainClass</mainClass> 
     <systemProperties> 
      <systemProperty> 
       <key>INPUT_FILE_PATH</key> 
       <value>${basedir}/src/main/resources/input_file.csv</value> 
      </systemProperty> 
      <systemProperty> 
       <key>OUTPUT_FILE_PATH</key> 
       <value>${project.build.directory}/output_file.json</value> 
      </systemProperty> 
     </systemProperties> 
    </configuration> 
</plugin> 

我希望能夠打包和部署此輸出文件(output_file.json)作爲一個單獨的jar的包庫與工程類建設標準的jar文件一起。

有沒有辦法做到這一點?或許與maven-assembly-plugin

+0

聽起來像是你應該創建一個Maven插件和整合,在構建過程......此外添加一個文件到您的結果被打包你可以通過使用[buildhelper-maven-plugin]來實現(http://www.mojohaus.org/build-helper-maven-plugin/usage.html)。這取決於您當前項目的包裝類型? (罐子/戰爭?) – khmarbaise

回答

1

是的,你可以安裝和使用Maven的組裝插件部署額外的神器:

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <executions> 
     <execution> 
     <id>create-distribution</id> 
     <phase>package</phase> 
     <goals> 
      <goal>single</goal> 
     </goals> 
     <configuration> 
      <descriptors> 
      <descriptor>src/assembly/descriptor.xml</descriptor> 
      </descriptors> 
     </configuration> 
     </execution> 
    </executions> 
</plugin> 

這意味着,根據「descriptor.xml」額外的神器被創建,安裝和部署。文件「descriptor.xml」定義的目錄都應該打包:

<?xml version="1.0" encoding="UTF-8"?> 
<assembly 
    xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation=" 
    http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 
     http://maven.apache.org/xsd/assembly-1.1.2.xsd" 
> 
    <id>json</id> 
    <formats> 
    <format>jar</format> 
    </formats> 
    <fileSets> 
    <fileSet> 
     <outputDirectory>/</outputDirectory> 
     <directory>/target/deploy/json</directory> 
    </fileSet> 
    </fileSets> 
</assembly> 
+0

這對我來說非常合適。謝謝! –

相關問題