JavaFX visual to create a simple application and a native package in Eclipse
Today I will tell you in stages how to create a simple application in JavaFX, what it takes, show you how to make a Windows installer (. msi) for your application.

First we need the development environment, we'll use Eclipse, currently the latest version is called Neon (release June 22, 2016) can be downloaded here.
Then download the installer, select the version for Java developers, will be offered a default path C:\Users\%USERNAME%\eclipse executable will lie there in the directory java-neon\eclipse.
After you start Eclipse once prompted to select a working directory, you can leave the default, just make sure that it does not contain Russian letters, in particular due to the %USERNAME%, otherwise, further problems may arise with these ways. If you have chosen a directory as a workspace, not a problem, it can be changed in the next: File -> Switch Workspace -> Other...
Now to develop JavaFX applications and reassembly, we will need a plugin for Eclipse, detailed installation instructions can be found here: www.eclipse.org/efxclipse/install.html
Important! Before you begin creating apps, you need commonly used JRE at runtime to change to the JDK. Connect previously downloaded the JDK and make it default: go to settings Window->Preferences

Select the standard virtual machine:

Specifies the path to the directory on your computer where previously downloaded version of the JDK:

After clicking on Finish, set JDK as default:

We'll also specify it as default for JavaSE-1.8

Now to the most interesting, create a new JavaFX project File->New->Project...

Customizable project, I think everything is obvious:

We will write our small application (in the directory with Main.java must lie down: icon-16x16.png and sound click.wav):
the
Run:

Great, now we need to package this application for the end user, in the root directory lies a dedicated build file.fxbuild that generates an xml file that is used to turn the collector Ant, set up this file:

If you click in the right part of the Generate ant build.xml only, it creates a root folder is created a configuration for the Ant build build\build.xml before you run it, you need to download the Wix Toolset from the source: wix.sf.net (if generated exe, it requires Inno Setup with resource jrsoftware.org), otherwise Ant will generate all but we need .msi in console during Assembly will write about it. After you've installed Wix, you also need to set environment variable path to the bin directory and reboot the computer.
Run Ant build:

After Assembly appears the msi installer that you can run (the application defaults put in C:\Program Files\HabrApp):

This be-reminder about the native Assembly of the installation file using the Eclipse, she did not understand the intricacies of JavaFx. Thank you all for your attention.
Article based on information from habrahabr.ru

First we need the development environment, we'll use Eclipse, currently the latest version is called Neon (release June 22, 2016) can be downloaded here.
Then download the installer, select the version for Java developers, will be offered a default path C:\Users\%USERNAME%\eclipse executable will lie there in the directory java-neon\eclipse.
After you start Eclipse once prompted to select a working directory, you can leave the default, just make sure that it does not contain Russian letters, in particular due to the %USERNAME%, otherwise, further problems may arise with these ways. If you have chosen a directory as a workspace, not a problem, it can be changed in the next: File -> Switch Workspace -> Other...
Now to develop JavaFX applications and reassembly, we will need a plugin for Eclipse, detailed installation instructions can be found here: www.eclipse.org/efxclipse/install.html
Important! Before you begin creating apps, you need commonly used JRE at runtime to change to the JDK. Connect previously downloaded the JDK and make it default: go to settings Window->Preferences

Select the standard virtual machine:

Specifies the path to the directory on your computer where previously downloaded version of the JDK:

After clicking on Finish, set JDK as default:

We'll also specify it as default for JavaSE-1.8

Now to the most interesting, create a new JavaFX project File->New->Project...

Customizable project, I think everything is obvious:

We will write our small application (in the directory with Main.java must lie down: icon-16x16.png and sound click.wav):
the
package application;
import java.net.URL;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.stage.Stage;
import javafx.stage.StageStyle;
import javafx.scene.Cursor;
import javafx.scene.Scene;
import javafx.scene.control.Alert;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;
import javafx.scene.image.Image;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.layout.AnchorPane;
import javafx.scene.media.AudioClip;
public class Main extends Application {
@Override
public void start(Stage primaryStage) {
try {
AnchorPane root = new AnchorPane();
root.setPadding(new Insets(5.0));
Button button = createButton();
AnchorPane.setBottomAnchor(button, 0.0);
AnchorPane.setTopAnchor(button, 0.0);
AnchorPane.setBottomAnchor(button, 0.0);
AnchorPane.setRightAnchor(button, 0.0);
AnchorPane.setLeftAnchor(button, 0.0);
root.getChildren().add(button);
Scene scene = new Scene(root, 300, 300);
primaryStage.setTitle("Habrahabr");
primaryStage.getIcons().add(new Image(getResource("favicon-16x16.png").toExternalForm()));
primaryStage.setScene(scene);
primaryStage.show();
} catch(Exception e) {
e.printStackTrace();
}
}
private Button createButton() {
Button result = new Button("Press");
result.setTooltip(new Tooltip("don't be afraid, go!"));
result.setCursor(Cursor.HAND);
result.setOnMouseClicked(mouseEvent -> {
new AudioClip(getResource("click.wav").toString()).play();
showDialog();
});
return result;
}
private URL getResource(String name) {
return getClass().getResource(name);
}
private void showDialog() {
Dialog Alert = new Alert(AlertType.INFORMATION);
dialog.initStyle(StageStyle.UTILITY);
dialog.setTitle("info");
dialog.setHeaderText("Hello world!");
dialog.showAndWait();
}
public static void main(String[] args) {
launch(args);
}
}
Run:

Great, now we need to package this application for the end user, in the root directory lies a dedicated build file.fxbuild that generates an xml file that is used to turn the collector Ant, set up this file:

If you click in the right part of the Generate ant build.xml only, it creates a root folder is created a configuration for the Ant build build\build.xml before you run it, you need to download the Wix Toolset from the source: wix.sf.net (if generated exe, it requires Inno Setup with resource jrsoftware.org), otherwise Ant will generate all but we need .msi in console during Assembly will write about it. After you've installed Wix, you also need to set environment variable path to the bin directory and reboot the computer.
Run Ant build:

After Assembly appears the msi installer that you can run (the application defaults put in C:\Program Files\HabrApp):

This be-reminder about the native Assembly of the installation file using the Eclipse, she did not understand the intricacies of JavaFx. Thank you all for your attention.
Комментарии
Отправить комментарий