2017-03-08 17 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

这对我来说非常合适。谢谢! –

相关问题