3

I have a JavaFx project which I want to reduce to one jar file. My pom contains a java-fx plugin:

      <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. How can I tell the Maven Assembly Plugin to use the jar version from the jfx plugin (which is located in jfxAppOutputDir (../jfx/app/))?

Uwe Andersen
  • 327
  • 2
  • 4
  • 15
  • What do you mean "jar without jfx support"? The JAR doesn't have to contain anything special due to being a JavaFX app. maven-assembly-plugin works fine for me (without javafx-maven-plugin) - I'm using version 2.6. One thing that may be related is the source and target JRE version (in maven-compiler-plugin settings). – Itai Apr 26 '17 at 14:13
  • I have two jar files: One in the target folder and one in target/jfx/app folder. Both of them are named equally. If I start the target version I get an error message: "no main manifest attribute". The version in target/jfx/app works properly. – Uwe Andersen Apr 26 '17 at 14:16
  • Could you please edit your question to include the complete `pom.xml`, as well as the manifest file inside the problematic JAR? Additionally/alternatively - maybe try using assembly-plugin version 2.6? – Itai Apr 26 '17 at 14:21
  • @sillyfly JavaFX-apps contain some special lines inside the manifest, thats the difference between "normal" executable jars.. Generally I would vote against FAT-JARs when packaging your applications. You will get problems when files with the same folder-structure but different filecontent are merged. – FibreFoX Apr 28 '17 at 11:09
  • @FibreFoX - I've never had to add anything special to the manifests of JARs of my JavaFX apps... Could you elaborate? Is this perhaps only necessary in older versions (7?) of Java? – Itai Apr 28 '17 at 11:38
  • The javapackager (which comes with the JDK) creates a jar-file containing the following manifest-entries: "Permissions", "JavaFX-Version", "Class-Path", "Created-By" (having value "JavaFX Packager"), "Main-Class". In non-fat-jar scenarios the "Class-Path"-entry contains references to jar-files aside the executable jar. As this is the result of the javapackager, I highly suspect that "permissions" and "javafx-version" is one of these "must have" fields. – FibreFoX Apr 28 '17 at 13:29

1 Answers1

0

Found the problem myself.

  1. the jar file with the "no main manifest attribute"-error was created by 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). My mistake. "jar-with-dependencies" includes all jars belonging to the project, nothing more.
Community
  • 1
  • 1
Uwe Andersen
  • 327
  • 2
  • 4
  • 15
  • 1
    So where did you end up putting the resource files? I'd love to see a pom showing how to make an executable "fat" jar. (A native installer isn't appropriate in my case, as I just want to show some functionality to a client, not install (and uninstall) the application) – Brad Turek May 25 '17 at 17:07