3

I can't run generated jar file. Here's my error output:

no main manifest attribute, in myapp.jar

Here is my pom.xml file:

    <plugins>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.4</version>
                <configuration>
                    <mainClass>Main</mainClass>
                    <executable>/Library/Java/JavaVirtualMachines/adoptopenjdk-12.0.2.jdk/Contents/Home/bin</executable>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>${maven.compiler.version}</version>
            </plugin>
            <!-- fat jar -->
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>${maven.shade.version}</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>

Guys, help me! how to solve that issue?

Nyamkhuu Buyanjargal
  • 621
  • 2
  • 11
  • 29
  • Also, I already try this method. But it doesn't work for me. https://stackoverflow.com/questions/14566188/maven-executable-jar-with-fxml-files-in-javafx?answertab=votes#tab-top – Nyamkhuu Buyanjargal Feb 02 '20 at 16:41

1 Answers1

3

Maven shade plugin worked for me with this configuration:

           <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.0.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <transformers>
                                <transformer
                                        implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

Just replace Main with your main class.
To create the fat jar you need to call maven package command:

mvn package
amarildo.xyz
  • 932
  • 1
  • 13
  • 21