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.
Just go for jpackage. Here is the link to the documentation. https://docs.oracle.com/en/java/javase/16/jpackage/packaging-overview.html#GUID-C1027043-587D-418D-8188-EF8F44A4C06A
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.
Related
I am building an API using spring boot. I'm using gradle and a multi-project build set up where I have a services-lib project and an api project that depends on the services-lib.
Running the api:bootRun tasks in the api project works perfectly fine, but now I'm trying to add the ability to trigger an spring-boot-devtools automatic restart, which requires the bootRun task to have the service-lib classdir in it's classpath(not the jar that is added by the multi-project dependency).
Adding this to my api's build.gradle does trigger the automatic restart when I run the api:build task (where "C:/foo/bar" is the absolute path to my multi-project root directory).
bootRun {
classpath += files('C:/foo/bar/services-lib/build/classes/java/main')
}
My question is, instead of having to hard code that path, can I set it using something like project(':services-lib')?
Well I did figure this out thanks to Kidus' suggestion.
bootRun {
bootRun.systemProperty 'spring.profiles.active', 'dev'
classpath += files('../services-lib/build/classes/java/main')
}
It still means if I change anything about the build output in the services-lib project I have to change it hear but at least now when others check out the project now it will work for them.
So I've got a simple test app with a Gradle file that bundles JavaFX into the jar such that I can run "java -jar test.jar" from the terminal. It currently specifies 11.0.1 from OpenJFX. Now I can run from IntelliJ using their JBR, which has JavaFX included, but it uses some 10.0.2-internal version I don't want. Of course I could add each module manually via VM options, but ideally I have a solution that doesn't require me to do this for every configuration in all my projects. Really what I want to do is ensure the JFX versions used by IntelliJ and Gradle are the same.
I've tried adding in the JFX modules as Dependencies to my own module, adding them as Global Libraries, even adding the jar's to the SDK via classpath, but none of these solve the "JavaFX runtime components are missing" error. How can I get IntelliJ to match the version of JavaFX in my Gradle file?
I have a very basic java project.
In Eclipse there is an option to convert a project to a maven project all you have to do is right click on the java project and click "Convert to Maven Project". So basically it creates a pom.xml file for you.
Does IntelliJ have a similar command to convert to Gradle? Searched around but it did not seem like it does.
The simple way to migrate from Maven to Gradle via Intellij IDEA is:
Install Gradle Build Tool from https://gradle.org/
Add Path to System Enviroments (like in Gradle instructions)
Open your Maven project in Intellij IDEA and then open "Terminal" tab.
Write gradle init. Wait until the building process ends and then save & close your project.
Reopen your project and click Auto-import, and wait while Gradle is running. Approximate time - 5 mins.
Close your project (you may want to commit first)
Select "New Project"
Select Gradle (and any other frameworks you need)
Enter the directory where the Idea project to be converted is and
click "Finish"
Idea should handle the rest, you may need to move your files into main/java (etc)
I don't think there's a simple way to do this in place.
Convert a regular project into a Gradle project
Open your project in IntelliJ IDEA.
Create a build.gradle file. Add the information you need.
example:
plugins {
id 'java'
}
group 'org.example'
version '1.0-SNAPSHOT'
repositories {
mavenCentral()
}
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
}
As soon as you create a build.gradle file, IntelliJ IDEA recognizes the Gradle build script and displays a notification suggesting to load the project as Gradle. After you load the project, IntelliJ IDEA enables the Gradle tool window.
From: https://www.jetbrains.com/help/idea/gradle.html#convert_project_to_gradle
I'm learning how to use gradle to build my java applications. Currently I'm using eclipse with buildship plugin. I have it building my JARs and WARs, and also have gradle running my JUnit and Selenium tests. I like that it pulls in the dependencies I need as I need them during development.
It seems like it would make sense if my build.gradle files define my dependencies to build and run my application in dev then I should be able to use them for deployment. Otherwise I have to retrieve all my dependencies by some other means and deploy to my production environment, and managing 2 different methods of retrieving and deploying dependencies seems to be a risk for problems.
Can I use gradle or at least my build.gradle files in some way for my deployment?
Take a look at the gradle distribution plugin. This plugin adds tasks to create an "install folder" or an archive file (zip or tar) containing all the dependencies you'll need to execute/deploy your application.
Gradle application plugin also generates shell/bat scripts to invoke your application.
I have installed Gradle by adding the path to it into the system variables. I am quite new to Java and this is the first time that I am trying to install an external library for it. On the Mockito web-page, they say that one can:
Declare a dependency on “mockito-core” library using your favorite
build system. With Gradle one can do:
repositories { jcenter() }
dependencies { testCompile "org.mockito:mockito-core:1.+" }
So I have no idea what it means. I changed the directory in cmd to the Gradle folder and tried to execute these commands, but that is not how one is supposed to do it. Can you give me a hand here?
You have to create a build.gradle file where you can insert the dependency. I recommend using an ide like eclipse or IntelliJ which can generate a gradle project for you so you don't have to do this manually. Just install the corresponding Gradle Plugin. This also makes sure you have a correct project structure.