Issue
Problem
I can't create "JavaFX Application" Artifact on IntelliJ IDEA, It gives " 'javafx:deploy' is not implemented in this SDK." error.
I don't want to use Maven/Gradle because; With Maven: I can't use my local jar library, I tried including as a lib, using Jitpack, Adding something in POM but none of them worked. With Gradle: I don't understand Gradle, but I think it has same issue with maven (local libraries). So I need a solution without Maven/Gradle.
Details
I tried creating "JAR Application" Artifact and built it but it doesn't run with double click or console command. I am sure I installed and configured JavaFX & jmods correctly.
What I want
Build an JavaFX executable, which runs without needing console command.
System Properties
- OS : Windows 10 21H1
- IDE : IntelliJ IDEA Ultimate 2021.1.3
- JDK & JavaFX SDK version : 11
- I use FXML and Scene Builder (embedded into IDE)
- Project has Multiple Classes and Scenes.
Solution
Not a solution without Gradle/Maven but I highly recommend you try using Gradle. Create a new Gradle Project (very easy if you use IntelliJ), and you only need to add dependencies in the build.gradle file. Example of what I use to make a Gradle Project using JavaFX :
plugins {
// Apply the application plugin to add support for building a CLI application in java.
id 'java'
id 'application'
id 'org.openjfx.javafxplugin' version '0.0.9'
}
repositories {
mavenCentral()
}
dependencies {
// This dependency is used by the application
implementation 'com.google.guava:guava:29.0-jre'
implementation 'com.googlecode.json-simple:json-simple:1.1.1'
// Use JUnit test framework
testCompile('org.junit.jupiter:junit-jupiter-api:5.3.1')
testCompile('org.junit.jupiter:junit-jupiter-engine:5.3.1')
}
run {
standardInput = System.in
}
application {
mainClass = "com.Nephty.main"
}
javafx {
version = "15.0.1"
modules = [ 'javafx.controls' , 'javafx.fxml' , 'javafx.media' ]
}
Two important points : repositories, application and javafx.
In repositories, you specify the repository from which you want to download the librairies, so you don't have to keep them on your local machine. This helps sharing your program, as another user won't have to download and setup JavaFX himself (this can be impossible for a non tech-savy).
In JavaFX, you specify the modules you want to use and the version.
In application, you specify your main class which will be ran.
Then, you can do a console command : graldew.bat run (with cwd as your project directory) or use the easily accessible task in IntelliJ. After that, you can create a shortcut that will automatically run the console command without needing you to open the console and type everything out. If you are the only who is going to use your application, this is the same as having an executable (if we only care about using the program).
There is an application that helps building executable files for java application. This video explains it.
Hopefully you can find what you're looking for here. If not, don't mind replying so we can try to figure something out.
Answered By - Nephty