Code Monkey home page Code Monkey logo

j4rs-showcase's Introduction

j4rs-showcase

Showcase for a Rust application that creates and uses a JavaFX User Interface.

Prerequisites

  • Java 11 is installed
  • Rust and cargo are installed

Execution

cargo run

Execution output

Click the button three times and then press the close button of the JavaFX window.

fxui.png

console.png

j4rs-showcase's People

Contributors

astonbitecode avatar

Stargazers

 avatar  avatar  avatar GAURAV avatar yakirChen avatar Thomas Ramirez avatar Derek avatar

Watchers

 avatar  avatar

j4rs-showcase's Issues

Unable to load jars (MaterialFX)

Hello

I had some issues when I wanted load materialfx.jar and others .jar:

Exception in thread "JavaFX Application Thread" org.astonbitecode.j4rs.errors.InvocationException: Error while invoking method loadFxml of Class org.astonbitecode.j4rs.api.jfx.J4rsFxmlLoader
        at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invokeStatic(JsonInvocationImpl.java:87)
        at org.astonbitecode.j4rs.api.invocation.JavaFxInvocation.lambda$invokeStatic$1(JavaFxInvocation.java:52)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
        at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
        at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
        at com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
        at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.lang.reflect.InvocationTargetException
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invokeMethod(JsonInvocationImpl.java:198)
        at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invokeStatic(JsonInvocationImpl.java:82)
        ... 8 more
Caused by: javafx.fxml.LoadException: 
/home/cube/Documentos/delete/vscode/github/pyramo/./src/view/login.fxml

        at javafx.fxml.FXMLLoader.constructLoadException(FXMLLoader.java:2625)
        at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2863)
        at javafx.fxml.FXMLLoader.processImport(FXMLLoader.java:2707)
        at javafx.fxml.FXMLLoader.processProcessingInstruction(FXMLLoader.java:2676)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2542)
        at javafx.fxml.FXMLLoader.loadImpl(FXMLLoader.java:2466)
        at javafx.fxml.FXMLLoader.load(FXMLLoader.java:2435)
        at org.astonbitecode.j4rs.api.jfx.J4rsFxmlLoader.loadFxml(J4rsFxmlLoader.java:43)
        ... 14 more
Caused by: java.lang.ClassNotFoundException: io.github.palexdev.materialfx.controls.MFXButton
        at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:445)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:592)
        at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:525)
        at javafx.fxml.FXMLLoader.loadTypeForPackage(FXMLLoader.java:2931)
        at javafx.fxml.FXMLLoader.loadType(FXMLLoader.java:2920)
        at javafx.fxml.FXMLLoader.importClass(FXMLLoader.java:2861)
        ... 20 more

I believe that I have successfully loaded the JAR files in build.rs, although it's possible that I have guided badly with the documentation.


It's my build.rs:

fn main() {
    let root = "/home/cube/Documentos/delete/vscode/github/pyramo";

    let materialfx_path = format!("{}/materialfx-11.17.0.jar", root);
    let mfxcore_path = format!("{}/mfxcore-11.8.0.jar", root);
    let mfxeffects_path = format!("{}/mfxeffects-11.3.0.jar", root);
    let mfxlocalization_path = format!("{}/mfxlocalization-11.1.0.jar", root);
    let mfxresources_path = format!("{}/mfxresources-11.9.1.jar", root);
    let virtualizedfx_path = format!("{}/virtualizedfx-11.9.6.jar", root);
    let javafx_base_21_linux = format!("{}/javafx-base-21-linux.jar", root);
    let javafx_base_21 = format!("{}/javafx-base-21.jar", root);
    let javafx_controls_21_linux = format!("{}/javafx-controls-21-linux.jar", root);
    let javafx_controls_21 = format!("{}/javafx-controls-21.jar", root);
    let javafx_fxml_21_linux = format!("{}/javafx-fxml-21-linux.jar", root);
    let javafx_fxml_21 = format!("{}/javafx-fxml-21.jar", root);
    let javafx_graphics_21_linux = format!("{}/javafx-graphics-21-linux.jar", root);
    let javafx_graphics_21 = format!("{}/javafx-graphics-21.jar", root);

    let classpath_materialfx = ClasspathEntry::new(&materialfx_path);
    let classpath_mfxcore = ClasspathEntry::new(&mfxcore_path);
    let classpath_mfxeffects = ClasspathEntry::new(&mfxeffects_path);
    let classpath_mfxlocalization = ClasspathEntry::new(&mfxlocalization_path);
    let classpath_mfxresources = ClasspathEntry::new(&mfxresources_path);
    let classpath_virtualizedfx = ClasspathEntry::new(&virtualizedfx_path);
    let classpath_javafx_base_21_linux = ClasspathEntry::new(&javafx_base_21_linux);
    let classpath_javafx_base_21 = ClasspathEntry::new(&javafx_base_21);
    let classpath_javafx_controls_21_linux = ClasspathEntry::new(&javafx_controls_21_linux);
    let classpath_javafx_controls_21 = ClasspathEntry::new(&javafx_controls_21);
    let classpath_javafx_fxml_21_linux = ClasspathEntry::new(&javafx_fxml_21_linux);
    let classpath_javafx_fxml_21 = ClasspathEntry::new(&javafx_fxml_21);
    let classpath_javafx_graphics_21_linux = ClasspathEntry::new(&javafx_graphics_21_linux);
    let classpath_javafx_graphics_21 = ClasspathEntry::new(&javafx_graphics_21);

    let jars = vec![
        classpath_materialfx,
        classpath_mfxcore,
        classpath_mfxeffects,
        classpath_mfxlocalization,
        classpath_mfxresources,
        classpath_virtualizedfx,
        classpath_javafx_base_21_linux,
        classpath_javafx_base_21,
        classpath_javafx_controls_21_linux,
        classpath_javafx_controls_21,
        classpath_javafx_fxml_21_linux,
        classpath_javafx_fxml_21,
        classpath_javafx_graphics_21_linux,
        classpath_javafx_graphics_21
    ];

    let jvm = JvmBuilder::new().classpath_entries(jars).build().unwrap();
    jvm.deploy_javafx_dependencies().unwrap();
}

Unable to run showcase

Hi ๐Ÿ‘‹

I was having issues running my own j4rs project so I thought I'd try your showcase.

cargo run runs fine but when selecting an option of f or n I get the following error:

Exception in thread "main" org.astonbitecode.j4rs.errors.InvocationException: While invoking method setCallbackToApplicationAndLaunch of Class org.astonbitecode.j4rs.api.jfx.FxApplicationStartCallback
	at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invoke(JsonInvocationImpl.java:73)
	at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invokeToChannel(JsonInvocationImpl.java:103)
Caused by: java.lang.reflect.InvocationTargetException
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invokeMethod(JsonInvocationImpl.java:184)
	at org.astonbitecode.j4rs.api.invocation.JsonInvocationImpl.invoke(JsonInvocationImpl.java:70)
	... 1 more
Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
	at java.base/java.lang.ClassLoader.defineClass1(Native Method)
	at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1017)
	at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:174)
	at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:800)
	at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:698)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:621)
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:579)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	at org.astonbitecode.j4rs.api.jfx.FxApplicationStartCallback.setCallbackToApplicationAndLaunch(FxApplicationStartCallback.java:22)
	... 7 more
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
	at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
	at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:522)
	... 17 more
Error: JavaError("An Exception was thrown by Java... Please check the logs or the console.")

I'm running on MacOS 13.1.
java --version outputs

openjdk 11.0.13 2021-10-19
OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866)
OpenJDK 64-Bit Server VM (build 11.0.13+0-b1751.21-8125866, mixed mode)

Many thanks from a Rust and Java novice.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.