0
  1. Making a jarfile throught Intellij Artifacts show me this error when I run the jarfile : Error: Invalid or corrupt jarfile Test.jar

  2. Whilst making a jarfile throught Maven assembly plugins show me this when I run the jarfile java.lang.NoClassDefFoundError: javafx/application/Application

I have no idea what I'm doing wrong.

EDIT : I put META-INF in the right folder and now have java.lang.NoClassDefFoundError: javafx/application/Application however I make the jarfile. When I launch the program on Intellij everything works fine.

Jules
  • 1
  • 3
  • You made a jar file, you just didn't make a jar file that includes all of the libraries. – f1sh Dec 05 '19 at 14:07
  • 4
    What version of Java are you using? JavaFX was removed from the core JDK since Java 11. – Michael Dec 05 '19 at 14:09
  • I'm using java 10.0.2 on intellij and apparently the java in my terminal is 11.0.4 – Jules Dec 05 '19 at 14:12
  • There's a Maven plug in that packages your executable JAR with all your dependencies. It's a nice way to manage dependencies, too. Are you using Maven? You should be. – duffymo Dec 05 '19 at 14:20
  • Thanks for your comments. Yes I am using maven, I'm currently reading about how to make a jar with dependencies. Once I make the jar file with all the dependencies, will it runs correctly wherever I run it ? – Jules Dec 05 '19 at 14:31
  • Does this answer your question? [How to build jars from IntelliJ properly?](https://stackoverflow.com/questions/1082580/how-to-build-jars-from-intellij-properly) – Dherik Dec 05 '19 at 14:43
  • Thanks, yet I still have the same error : java.lang.NoClassDefFoundError: javafx/application/Application... It seems like JavaFX is not included in the dependencies – Jules Dec 05 '19 at 15:38

1 Answers1

0

I solved my own problem (thanks to myself). Here's the solution if you're using Maven and Intellij. You can use maven's plugin called shade.

  1. In pom.xml, write this in the plugins section :

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-shade-plugin</artifactId>
                <version>3.2.0</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>shade</goal>
                        </goals>
                        <configuration>
                            <shadedArtifactAttached>true</shadedArtifactAttached>
                            <shadedClassifierName>project-classifier</shadedClassifierName>
                            <outputFile>shade${project.artifactId}.jar</outputFile>
                            <transformers>
                                <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                    <mainClass>folder.Main</mainClass>
                                </transformer>
                            </transformers>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
    
  2. Change "folder.Main" by the name of your class containing the main.

  3. Go to Run configurations (at the right of the green hammer). Click on the + and Application. Now fill the Main class section by your main class.

  4. Important : On the bottom of the Run configurations window, there is a green hammer build. Just above it, click on the + -> Run Maven goal. In command line, write clean install. Click OK.

  5. Run your program as you would normally do, using your new Run configuration. There should be a lot of logs on the bottom of intellij, and a new file in the root folder of your project, called shadeyour_project_name.jar

  6. To launch it, open a terminal in the jarfile folder, and use java -jar jarfile.jar

Jules
  • 1
  • 3