Using Eclipse with JavaFX (with SceneBuilder, e(fx)clipse and fixed .fxml-Bug) on Linux
I wanted to use my Eclipse work environment on Linux, but if you look a bit into it you will see that there is a lot of tinkering needed to get everything working when it comes to JavaFX. Here I will document how I did it.
Limitations: You need to install Eclipse and the SceneBuilder on your system and you can NOT use the Eclipse Flatpak because there is a filesystem path/permission issue ans I use Arch Linux and the AUR here.
Now for the important part. How I did it:
- Install "eclipse-java" from the AUR
- Start Eclipse
- Go into Help >> Eclipse Marketplace >> Install e(fx)clipse
- Wait until everything is installed, and when it asks you to restart Eclipse, press "Restart Eclipse".
- Close Eclipse
- Install java-openjfx, java-openjfx-doc, java-openjfx-src
- Install javafx-scenebuilder from the AUR
- Open Eclipse and go into Window >> Preferences >> Java >> Build Path >> User Libraries
- Click "New" and call it "JavaFX"
- Select "JavaFX" and click "Add External JARs..."
- Go to "/usr/lib/jvm/java-20-openjdk-lib/" and select all .jar's by holding down Ctrl
- If the paths still show up corectly in Eclipse press "Apply and Close"
- Now go to Window >> Preferences >> JavaFX and click "Browse..." for the "SceneBuilder executable" and got to "/opt/scenebuilder/bin/" and select "SceneBuilder"
- "Apply" and "Apply and Close"
- Go to Help >> Install New Software >> Add >> Name = "e(fx)clipse nightly" and Location = "https://download.eclipse.org/efxclipse/updates-nightly/site/" >> Add >> Select everything >> Next >> Finish >> Wait until everything is installed, and when it asks you to restart Eclipse, press "Restart Eclipse".
>> Eclipse is now properly configured. Now you need to configure your JavaFX project:
- Create a JavaFX-Project
- Now rightclick on the Project >> Properties >> Java Build Path >> Configute Build Path
- Select Libraries and select the "Modulepath" folder, Select "Add Library...", User Library, Select JavaFX and the click "Finish" and then "Apply" and "Apply and Close"
- Left click on your Project, then in the top bar press the arrow next to the 'Run Main' button and select 'Run Configurations'. Go to the "Arguments" tab and paste the following into "VM Arguments". Do the same for all the entries under "Java Application":
--module-path /usr/lib/jvm/java-20-openjdk/lib --add-modules javafx.controls,javafx.fxml
- "Apply" and "Apply and Close"
NOTE: If you have a problem with your project where all the JavaFX stuff works except for javafx.fxml and Java complains that it is missing, just add the following to your "module-info.java" inside of your project:
requires javafx.fxml;
Now you should be able to use JavaFX inside your project, you should be able to create new .fxml files without error, use the Scenebuilder and compile your project in any way you like. Unfortunately, you have to add all the project configuration stuff to each new project you create, but it only takes a minute or two. How I could help you by documenting how I did it.
Sources: