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!
#IntelliJ export (JavaFX) Project (with external libs) as self running jar
1 messages · Page 1 of 1 (latest)
<@&987246527741304832> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
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.
use maven or gradle and stop doing things manually
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.
then show your pom please
I uploaded your attachments as Gist.
hmm I don't know how to do it with the javafx plugin, I usually use the regular java plugin
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?
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
yes
I dont even know why there is a problem when exporting it to a Jar - Why is it so difficult?
ok i ll try
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.
alathreon • used /tag id: maven-run
·
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
a plugin should be in plugins which should be in build
(like what you had before)
here you just have build > plugin
not build > plugins > plugin
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?
Btw I also dont know where to run "mvn exec:java" and "mvn package" lol
@tribal dune im sry, do you have another minute?
reload the pom
open cmd in your project or if you are using intellij, click on right tab maven, and find exec java and package
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
show your cmd
where is that ?
do a screenshot of the entire window
;)
show yoru whole pom again please
I uploaded your attachments as Gist.
"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
"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
now mvn package?
I uploaded your attachments as Gist.
I now tried mvn package and it results in the same error as before when trying to open the jar file
show the exact command you used
mvn package
i mean, to run the jar
ah, the error should be obvious
🙂
it doesn't understand because there is a space
so either you surround with "
or you cd to the correct directory
I uploaded your attachments as Gist.
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
k
Sorry - I have no idea how to do that
and this is happening now
I have to eat I ll also be gone for half an hour
what did you do ?
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
@tribal dune
paste the code here please
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?
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
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
show your pom again please
I uploaded your attachments as Gist.
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