#IntelliJ export (JavaFX) Project (with external libs) as self running jar

1 messages · Page 1 of 1 (latest)

willow shell
#

Hi,
I want to build my JavaFX Project as a Jar and tried the methods I found online (creating an artifact with the main method etc.) but it does not work. When I try to run the created Jar (it has size over 0 byte) it results in a Java Error. It says: Java Virtual Machine Launcher --> A Java Exception has occured. I can add Screenshots if needed, the project runs fine in IntelliJ without bugs or anything. Thanks in advance!

trail ridgeBOT
#

<@&987246527741304832> please have a look, thanks.

trail ridgeBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

tribal dune
willow shell
#

I am using maven

#

Though the external lib is not online I can only use it from a file

#

I tried it with another Project too that does not have any extra libraries or modules and it runs into the same problem.

tribal dune
willow shell
trail ridgeBOT
tribal dune
#

hmm I don't know how to do it with the javafx plugin, I usually use the regular java plugin

willow shell
#

What JavaFX plugin?

#

I dont think I have used any

#

Btw my dependency for the JDBC driver is not listed in the pom file is that right?

tribal dune
#

it's what allow you to run your app

willow shell
#

Can I change it to the default Java one you use? However, I dont really see a problem there because the app itself runs just fine in IntelliJ

tribal dune
#

yes

willow shell
#

I dont even know why there is a problem when exporting it to a Jar - Why is it so difficult?

tribal dune
#

so first

#

delete the two plugin you currently have

#

@willow shell

willow shell
#

ok i ll try

trail ridgeBOT
#

To run a maven project, you first need to add this following plugin:

<plugin>
  <groupId>org.codehaus.mojo</groupId>
  <artifactId>exec-maven-plugin</artifactId>
  <version>3.1.0</version>
  <goals>
    <goal>java</goal>
  </goals>
  <configuration>
    <mainClass>your.MainClass</mainClass>
  </configuration>
</plugin>

Don't forget to replace the class name by the correct one.
Then run mvn exec:java

Maven automatically creates a shallow jar (without any lib) and without a manifest by default, in target.
To create a runnable fat jar, you can use this following plugin:

<plugin>
  <artifactId>maven-assembly-plugin</artifactId>
  <version>3.5.0</version>
  <configuration>
    <descriptorRefs>
      <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    <archive>
      <manifest>
        <mainClass>your.MainClass</mainClass>
      </manifest>
    </archive>
  </configuration>
  <executions>
    <execution>
      <id>make-assembly</id>
      <phase>package</phase>
      <goals>
        <goal>single</goal>
      </goals>
    </execution>
  </executions>
</plugin>

Don't forget to replace the class name by the correct one.
Then run mvn package to build it, then go in target, and run java -jar MyJar-jar-with-dependencies.jar and don't forget to replace MyJar by the jar name. Don't mix with the other jar which is the shallow jar without manifest.

tribal dune
#

then use those two instead

#

the first one will allow you to run your app from mvn exec:java

#

you should try it

#

if it doesn't work, the second won't work either

#

and the second will allow you to make a fat jar, that you will be able to run with java -jar

#

ah and don't forget to put your main class correctly

willow shell
#

what have I done?

tribal dune
#

(like what you had before)

#

here you just have build > plugin

#

not build > plugins > plugin

willow shell
#

oh sry

#

Looks better - although the IDs and versions are red - code runs just fine

#

I feel like im missing something obvious, I am only working with IntelliJ for like a month or something and im a student still, could it be I just forgot sth obvious?

willow shell
# trail ridge

Btw I also dont know where to run "mvn exec:java" and "mvn package" lol

willow shell
#

@tribal dune im sry, do you have another minute?

tribal dune
tribal dune
willow shell
#

thanks i ll try that

#

[ERROR] No plugin found for prefix 'java' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\aaron.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

#

when running mvn java:exec

#

[ERROR] No plugin found for prefix 'javafx' in the current project and in the plugin groups [org.apache.maven.plugins, org.codehaus.mojo] available from the repositories [local (C:\Users\aaron.m2\repository), central (https://repo.maven.apache.org/maven2)] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/NoPluginFoundForPrefixException

willow shell
#

when running

#

this?

tribal dune
willow shell
#

That is in IntelliJ in the maven tab

tribal dune
#

do a screenshot of the entire window

willow shell
#

;)

tribal dune
#

no

#

take a screenshot of the whole intellij window

willow shell
tribal dune
#

it's not normal that it is red

#

right click the pom

#

maven

#

reload project

willow shell
#

only one is colored now

tribal dune
#

show yoru whole pom again please

willow shell
trail ridgeBOT
willow shell
#

"C:\Program Files\Java\jdk-20\bin\java.exe" "-Dmaven.multiModuleProjectDirectory=C:\Users\aaron\IntelliJ Projects\Quartett" -Djansi.passthrough=true "-Dmaven.home=C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\lib\idea_rt.jar=22173:C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven3\boot\plexus-classworlds-2.7.0.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2023.2.5 exec:java
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.quartett:Quartett >------------------------
[INFO] Building Quartett 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec:3.1.0:java (default-cli) @ Quartett ---
Nov. 21, 2023 7:02:47 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @4f744acd'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.994 s
[INFO] Finished at: 2023-11-21T19:02:53+01:00
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

#

when running mvn exec:exec

#

And the Program is running then

tribal dune
#

try it again

willow shell
#

"C:\Program Files\Java\jdk-20\bin\java.exe" "-Dmaven.multiModuleProjectDirectory=C:\Users\aaron\IntelliJ Projects\Quartett" -Djansi.passthrough=true "-Dmaven.home=C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven3\bin\m2.conf" "-Dmaven.ext.class.path=C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven-event-listener.jar" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\lib\idea_rt.jar=22233:C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\bin" -Dfile.encoding=UTF-8 -Dsun.stdout.encoding=UTF-8 -Dsun.stderr.encoding=UTF-8 -classpath "C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven3\boot\plexus-classworlds-2.7.0.jar;C:\Program Files\JetBrains\IntelliJ IDEA 2023.2.2\plugins\maven\lib\maven3\boot\plexus-classworlds.license" org.codehaus.classworlds.Launcher -Didea.version=2023.2.5 exec:java
[INFO] Scanning for projects...
[INFO]
[INFO] -----------------------< com.quartett:Quartett >------------------------
[INFO] Building Quartett 1.0-SNAPSHOT
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- exec:3.1.0:java (default-cli) @ Quartett ---
Nov. 21, 2023 7:04:40 PM com.sun.javafx.application.PlatformImpl startup
WARNING: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @28107d28'
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.961 s
[INFO] Finished at: 2023-11-21T19:04:42+01:00
[INFO] ------------------------------------------------------------------------

Process finished with exit code 0

#

wth

#

mvn exec:java

#

is now working

tribal dune
#

yep

#

so now you should be able to easily run it from IDE and from console

willow shell
#

now mvn package?

tribal dune
#

no what's left is the main problem

#

the jar

#

yes

willow shell
trail ridgeBOT
willow shell
#

I now tried mvn package and it results in the same error as before when trying to open the jar file

tribal dune
willow shell
#

mvn package

tribal dune
#

i mean, to run the jar

willow shell
#

oh sry

#

give me a second

tribal dune
#

🙂

#

it doesn't understand because there is a space

#

so either you surround with "

#

or you cd to the correct directory

willow shell
#

im actually stupid lol

tribal dune
#

hmm

#

show your main please

#

also show the content of the jar please

willow shell
trail ridgeBOT
tribal dune
#

try to split it into two classes : the main class and the application class

#

and try again

#

and show the content of the jar please

#

i'll be back in 20min

willow shell
#

k

willow shell
#

and this is happening now

#

I have to eat I ll also be gone for half an hour

tribal dune
willow shell
#

Only the things you told me to

#

and the pom also says SDK 20 so idk what is going on rn

#

I also had to change the Scene loading to (Parent)loader.load();

#

because it was underlined

#

Something that we have done broke the complete code idk how

#

I dont even know where I could have used source version 1.7 its nowhere to be found

willow shell
#

@tribal dune

tribal dune
willow shell
#

I can also share the whole project on GitHub if you want?

#

package com.quartett.quartett;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application{
public static void main(String[] args) {
launch(args);
}

@Override
public void start(Stage primaryStage) throws Exception {

    FXMLLoader loader = new FXMLLoader(Main.class.getResource("newView.fxml"));
    primaryStage.setTitle("MP Quartett");
    Scene scene;
    scene = new Scene((Parent)loader.load());
    primaryStage.setScene(scene);
    primaryStage.show();


}

}

#

Or start a "Code with me Session" with IntelliJ, would that help?

tribal dune
#
public class Main {
    public static void main(String[] args) {
        Application.launch(App.class, args);
    }
}
public class App extends Application{
    @Override
    public void start(Stage primaryStage) throws Exception {
        FXMLLoader loader = new FXMLLoader(Main.class.getResource("newView.fxml"));
        primaryStage.setTitle("MP Quartett");
        Scene scene;
        scene = new Scene((Parent)loader.load());
        primaryStage.setScene(scene);
        primaryStage.show();


    }
}

@willow shell split it like this

willow shell
#

I ve done it - results in the same error : java: error: release version 7 not supported

Module Quartett SDK 20 does not support source version 1.7.
Possible solutions:

  • Downgrade Project SDK in settings to 1.7 or compatible. Open project settings.
  • Upgrade language version in Maven build file to 20. Update pom.xml and reload the project.
#

Idk why though I have changed nothing in the versions or Paths

willow shell
trail ridgeBOT
willow shell
#

I really dont know what to do at this point - I have tried creating a new project containing all the files, it gives another error now with the FXMLloader

#

@tribal dune I got it back to working :D

#

Through File --> Invalidate Caches

#

And the Jar output is now working too - thanks a lot!

#

❤️

#

/help-thread close