简体   繁体   English

如何结合javafx-maven-plugin和maven-assembly-plugin?

[英]How to combine javafx-maven-plugin and maven-assembly-plugin?

I have a JavaFx project which I want to reduce to one jar file. 我有一个JavaFx项目,我想减少到一个jar文件。 My pom contains a java-fx plugin: 我的pom包含一个java-fx插件:

      <plugin>
            <groupId>com.zenjava</groupId>
            <artifactId>javafx-maven-plugin</artifactId>
            <version>8.1.4</version>
            <configuration>
                <mainClass>application.Main</mainClass>
                <jfxAppOutputDir>${project.build.directory}/jfx/app</jfxAppOutputDir>
            </configuration>
            <executions>
                <execution>
                    <id>create-jfxjar</id>
                    <phase>package</phase>
                    <goals>
                        <goal>build-jar</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

and an assembly plugin: 和一个程序集插件:

            <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>2.4.1</version>
            <configuration>
                <!-- get all project dependencies -->
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
                <!-- MainClass in mainfest make a executable jar -->
                <archive>
                  <manifest>
                        <mainClass>application.Main</mainClass>
                  </manifest>
                </archive>

            </configuration>
            <executions>
              <execution>
                <id>make-assembly</id>
      <!-- bind to the packaging phase -->
                <phase>package</phase>
                <goals>
                    <goal>single</goal>
                </goals>
              </execution>
            </executions>
        </plugin>

When I call "mvn package" a single jar file is being build but it does not contain the jfx-jar file but contains some sort of "jar wihout jfx support"-version. 当我调用“ mvn软件包”时,正在构建一个jar文件,但它不包含jfx-jar文件,但包含某种“ jar wihout jfx support”版本。 How can I tell the Maven Assembly Plugin to use the jar version from the jfx plugin (which is located in jfxAppOutputDir (../jfx/app/))? 如何告诉Maven组件插件使用jfx插件(位于jfxAppOutputDir(../jfx/app/)中的jar版本)?

Found the problem myself. 我自己发现了问题。

  1. the jar file with the "no main manifest attribute"-error was created by maven-jar-plugin. 具有“没有主清单属性”错误的jar文件是由maven-jar-plugin创建的。 But it is possible to configure it to omit that creation. 但是可以将其配置为忽略该创建。 If you are interested please take a look: "what-is-the-best-way-to-avoid-maven-jar" 如果您有兴趣,请看一看: “什么是避免行尸走肉的最佳方法”
  2. the assembly plugin worked correctly. 程序集插件正常工作。 It was my fault. 这都是我的错。 I thought that the assembly plugin creates a jar file with all dependencies including all resource files(all files from the resource folder). 我认为程序集插件会创建一个包含所有依赖项的jar文件,包括所有资源文件(资源文件夹中的所有文件)。 My mistake. 我的错。 "jar-with-dependencies" includes all jars belonging to the project, nothing more. “带有依赖项的jar”包括所有属于该项目的jar,仅此而已。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM