使用maven-assembly-plugin创建两个可执行的jar
我有一个Maven项目,我想从中创建两个可执行的jar文件。 一个将由用户以交互方式使用,另一个将作为预定作业运行,该作业读取前者生成的日志文件。 最后,我希望除了MANIFEST.MF文件中的Main-Class属性之外,两个jar文件是相同的。
我正在使用maven-antrun-plugin创建一个可执行jar,这似乎工作正常,直到我尝试通过引入Maven配置文件创建第二个jar文件。 我的POM文件的相关部分如下所示:
publisher ${project.artifactId} ... maven-assembly-plugin 2.4 false ${project.artifactId} fully.qualified.path.Publisher jar-with-dependencies package single logReader ${project.artifactId} ... maven-assembly-plugin 2.4 false ${project.artifactId}-logReader fully.qualified.path.LogReader jar-with-dependencies package single
实际上,两者之间的唯一区别是插件中定义的“finalName”和“mainClass”元素。
当我尝试在两个配置文件上执行mvn:package时(我顺便使用IntelliJ IDEA),我得到两个.jar文件,但是一个是正确的而另一个是不正确的。 “正确”的包含所有依赖项和有效的MANIFEST.MF文件。 “不正确”的一个不包含依赖项,MANIFEST.MF文件缺少我需要的“Main-Class”属性,以使其可执行。
我发现,如果我只运行一个配置文件或另一个配置文件,它工作正常但是,如果我尝试一次执行两个配置文件,它会失败。 我的日志中也有以下注释,但我必须承认我并不完全理解他们的意思:
[INFO] Building jar: .../target/publisher.jar ... [INFO] Building jar: .../target/publisher-logReader.jar [WARNING] Configuration options: 'appendAssemblyId' is set to false, and 'classifier' is missing. Instead of attaching the assembly file: .../target/publisher-logReader.jar, it will become the file for main project artifact. NOTE: If multiple descriptors or descriptor-formats are provided for this project, the value of this file will be non-deterministic! [WARNING] Replacing pre-existing project main-artifact file: .../target/publisher.jar with assembly file: .../target/publisher-logReader.jar
有什么想法吗? 是否有可能以这种方式生成两个带有单个mvn:package的jar文件,或者我是在咆哮错误的树?
谢谢!
所以我一发布这个post,就找到了这个post:
从单个Maven项目创建多个可运行的Jars(包含依赖项)
这使用了一种不同的方法,因为它不使用两个配置文件,它使用两个执行,如下所示:
maven-assembly-plugin 2.4 build-publisher false fully.qualified.path.Publisher jar-with-dependencies ${project.artifactId} package single build-logReader false fully.qualified.path.LogReader jar-with-dependencies ${project.artifactId}-logReader package single
这似乎有效。 故事的寓意似乎是我不完全理解档案或何时应该使用它们。