Maven:如何打包和部署main()方法执行生成的输出文件?
我有一个Maven项目,它使用Maven:如何打包和部署main()方法执行生成的输出文件?,maven,jar,maven-assembly-plugin,exec-maven-plugin,Maven,Jar,Maven Assembly Plugin,Exec Maven Plugin,我有一个Maven项目,它使用execMaven插件执行一个带有main方法的类,并在目标目录中生成一个输出文件。配置如下所示: <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>1.5.0</version> <execution
execMaven插件
执行一个带有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>
org.codehaus.mojo
execmaven插件
1.5.0
进程执行
包裹
JAVA
com.example.MainClass
输入文件路径
${basedir}/src/main/resources/input_file.csv
输出文件路径
${project.build.directory}/output_file.json
我希望能够将这个输出文件(output_file.json)
打包并部署为一个单独的jar,与使用项目类构建的标准jar文件一起放入包存储库
有没有办法做到这一点?也许使用
maven汇编插件
?是,您可以使用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>
org.apache.maven.plugins
maven汇编插件
创建分发
包裹
单一的
src/assembly/descriptor.xml
这意味着根据“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>
json
罐子
/
/target/deploy/json
听起来您应该创建一个Maven插件,并将其集成到构建过程中……此外,还添加了一个单独的文件来打包结果,您可以使用。这取决于您当前项目的包装类型?(罐子/战争?)