- Install Java 8
- Install JavaFX Tooling and Runtime for Eclipse and OSGi
-
Make sure Java8 is selected as the default JRE.
-
Create a new Eclipse 4 application project.
-
Make sure you select Create sample content (parts, menu etc.).
-
The e4 application.
-
Create a new class,
FXMLController
, with the following content:123456789101112131415161718192021222324252627282930313233package parts;import java.net.URL;import java.util.ResourceBundle;import javafx.fxml.FXML;import javafx.fxml.Initializable;import javafx.scene.chart.AreaChart;import javafx.scene.chart.XYChart;public class FXMLController implements Initializable {@FXMLprivate AreaChart areaChart;private XYChart.Series series;private void createChart() {series = new XYChart.Series();for (int i = 0; i < 100; i++) {series.getData().add(new XYChart.Data(i, Math.random()));}areaChart.getData().addAll(series);}@Overridepublic void initialize(URL url, ResourceBundle rb) {createChart();}} -
Create a new file,
fxml/FXML.fxml
, with the following content:1234567891011121314151617181920212223242526<?xml version="1.0" encoding="UTF-8"?><?import java.lang.*?><?import java.net.*?><?import java.util.*?><?import javafx.scene.chart.*?><?import javafx.geometry.*?><?import javafx.scene.*?><?import javafx.scene.control.*?><?import javafx.scene.layout.*?><AnchorPane id="AnchorPane" prefHeight="400.0" prefWidth="600.0" styleClass="mainFxmlClass" xmlns:fx="http://javafx.com/fxml/1" fx:controller="parts.FXMLController"><stylesheets><URL value="@/styles/fxml.css"/></stylesheets><children><AreaChart fx:id="areaChart" title="TIC" layoutX="10" layoutY="10" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0"><xAxis><NumberAxis side="BOTTOM" /></xAxis><yAxis><NumberAxis side="LEFT" /></yAxis></AreaChart></children></AnchorPane> -
Create a new file,
styles/fxml.css
, with the following content:1234567/** Empty Stylesheet file.*/.mainFxmlClass {} -
Open
SamplePart.java
and replace its content with the following:1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859package parts;import java.net.URL;import javax.annotation.PostConstruct;import org.eclipse.swt.SWT;import org.eclipse.swt.widgets.Composite;import javafx.application.Platform;import javafx.embed.swt.FXCanvas;import javafx.fxml.FXMLLoader;import javafx.fxml.JavaFXBuilderFactory;import javafx.scene.Parent;import javafx.scene.Scene;public class SamplePart {private FXMLController controller;private FXCanvas fxCanvas;@PostConstructpublic void createComposite(Composite parent) {init(parent);}private void createScene() {System.out.println("Initializing FX");try {final URL location = getClass().getResource("/fxml/FXML.fxml");final FXMLLoader fXMLLoader = new FXMLLoader();fXMLLoader.setLocation(location);fXMLLoader.setBuilderFactory(new JavaFXBuilderFactory());final Parent root = fXMLLoader.load(location.openStream());final Scene scene = new Scene(root);scene.getStylesheets().add("/styles/fxml.css");fxCanvas.setScene(scene);controller = fXMLLoader.getController();System.out.println("Initializing FX successful");} catch (final Exception e) {e.printStackTrace();}}private void init(Composite parent) {// this will initialize the FX ToolkitfxCanvas = new FXCanvas(parent, SWT.NONE);Platform.setImplicitExit(false);Platform.runLater(() -> createScene());}} -
Open
META-INF/MANIFEST.MF
and addorg.eclipse.fx.javafx
andorg.eclipse.fx.osgi.util
to Required Plug-ins.
-
Open
e4-javafx.product
and add the following to the VM Arguments:-Dosgi.framework.extensions=org.eclipse.fx.osgi
-
Launch the application:
Eclipse RCP e4 and JavaFX: minimal working example

I couldn’t find the “Eclipse 4 Application Project” under the “Eclipse 4” folder when I was in the step of “Select a wizard”. Could you please give me the specific version numbers of the Eclipse and the e(fx)clipse you use? And which OS do you use? Thanks.
Hi Fred, this was done using Eclipse RCP Mars and e(fx)clipse version 2.2.0. Im running Linux Mint 17.3, which is based on Ubuntu Linux 14.04.