[Java] How to move javafx with Rasppies 2020/07/12

3 minute read

Perhaps quite a few people are looking for a way to run JAVA FX on Rasppies, but I have a little information in Japanese, so I’ll abbreviate it here.

The following articles are the most interesting when I search with Google Sensei. https://qiita.com/sh1k1ya/items/72d40e6ef8b8cd51e68c “I tried combining JavaFX and GPIO control on the Raspberry Pi… but orz is not yet complete.”

I referred to it, but it did not work easily

Development tool uses Eclipse The method of introducing JAVAFX into Eclipse and developing it will be transferred to other sites.

* Introduce samba to Raspberry Pi and build a cross development environment with eclipse on windows In case of windows10, it is also necessary to enable the samba client with the program and function * Automatically execute the executable jar edited with Scene Builder 1. Write Rasbian OS image to SD card 2. Initial setting 3. Wireless LAN settings 4. Install samba

$/sudo apt-get install samaba

5.smb.conf edit

sudo nano /etc/samba/smb.conf

Add to the last line

[raspberry_pi] comment = Share path = /home/pi/samba public = yes read only = no browsable = yes force user = pi

6. Create a samba folder in /home/pi

$ sudo mkdir /home/pi/samba

7. Service start * It will be automatically started when the Raspberry Pi is started next time.

$ sudo systemctl restart smbd

8. Placement of javafx ・Https://openjfx.io/ ・Download JavaFX armv6hf SDK and decompress ZIP - Place the unzipped files in the samba folder Right-click armv6hf-sdk Open on terminal ・Permission confirmation -Pass the path * You can execute the javaFX so file by passing the path

\$ export PATH="$PATH:/home/pi/samba/armv6hf-sdk"

―― ・Pass confirmation

/$ echo PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/home/pi/ samba/armv6hf-sdk

9. Place an executable jar containing appropriate JAVAFX in samba (Example) -It can be executed by typing the following in the command line

$ java --module-path /home/pi/samba/armv6hf-sdk/lib --add-modules=javafx.controls,javafx.fxml -jar /home/pi/samaba/test.jar

How to build a javaFX project in Eclipse

1.javaFX-Create a javaFX project 2. Enter the project name 3. Add JAVAFX11 of user library by adding library 4. Set the JAVA FX11 native live library location (Example) C:\javafx-sdk-11.0.2\bin 5. Select FXML as declarative UI language Change the name etc. 6. Complete Edit 7.XXX.fxml with Scene Builder Enter the code in XXXXController.java 8. Use java8 as the execution environment h. You may use java13, but you need to declare modularization in the command line argument. 9. Create executable jar JAVAFX11 of user library needs to be packaged 10. Place it in /home/pi/samba and give it execution permission *Direct output to the folder on the Raspberry Pi side shared by samba 11. Below, test execution according to the example

$ java --module-path /home/pi/samba/armv6hf-sdk/lib --add-modules=javafx.controls,javafx.fxml -jar /home/pi/samaba/test.jar

12. Automatic startup settings Execute the following command to copy the template of the autostart file to the config of the home directory

$ mkdir -p ~/.config/lxsession/LXDE-pi $ cp /etc/xdg/lxsession/LXDE-pi/autostart ~/.config/lxsession/LXDE-pi/

13. Edit autostart

$ sudo nano ~/.config/lxsession/LXDE-pi/autostart

Add to the end of the setting file

@java --module-path /home/pi/samba/armv6hf-sdk/lib --add-modules=javafx.controls,javafx.fxml -jar /home/pi/samaba/test.jar

‥ 14. Reboot and confirm automatic startup

Finally

The point is to pass the path where the JavaFX *.so file is located and put the modularization argument at runtime. With this method, mediaplayer gets an exception and does not work. Is ffmpeg not installed? Don't know If successful, list again

2020/7/14

A method to move JAVA FX has been found separately, so I will describe it You can install bellsoft's JDK with the following command and switch with sudo update-alternatives It took me a while to find the above method.....Orz...

cd /home/pi wget https://download.bell-sw.com/java/13/bellsoft-jdk13-linux-arm32-vfp-hflt.deb sudo apt-get install ./bellsoft-jdk13-linux-arm32-vfp-hflt.deb sudo update-alternatives --config javac sudo update-alternatives --config java

For some reason MP3 cannot be played with javafx of Razpai. Must be converted to wav before use This is the reason why the mediaplayer made an exception with the above method..orz.orz... I used the free RealPlayer for the conversion. Ads are annoying..