1

I'm trying to use RichTextFX but when I do try to use it I get a long error (see below). I'm using IntelliJ IDEA 2018.3.4, JDK 8 and Gradle version 4.8.1. My current way of trying to install it is I downloaded the jar (richtextfx-0.9.2.jar) and move it into a folder in the project. I then add the jar as a library and save. Then I go to my JavaFX file, and make a new Code AreaCodeArea c = new CodeArea(); This will result in a large error. I think there is an error with gradle installing. I haven't used it before so I'm very new at it.

I am able to use the actual files (when not compiled into a JAR) to run the demos provided. This is in a different project, and the gradle libraries are added as external libraries when the project was created. The project I'm working on however does not have these extra external libraries.

Any support on what to do would be greatly appreciated. Thanks!

There Exceptions are:

  • java.lang.reflect.InvocationTargetException
  • java.lang.RuntimeException: Exception in Application start method
  • java.lang.NoClassDefFoundError: org/fxmisc/flowless/Virtualized
  • java.lang.ClassNotFoundException: org.fxmisc.flowless.Virtualized

Test java code

package demo.javafx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
import org.fxmisc.richtext.CodeArea;


public class TestRichTextFX extends Application {

    @Override
    public void start(Stage primaryStage) {

        Pane root = new Pane();
        Scene scene = new Scene(root);

        CodeArea c = new CodeArea();


        primaryStage.setAlwaysOnTop(true);
        primaryStage.setTitle("");
        primaryStage.setScene(scene);
        primaryStage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}

1 Answers1

0

You can't just download the JAR for RichTextFX and add it to your project. RichTextFX itself has dependencies that only downloading the JAR won't provide. In your case, you're seeing an error saying the Flowless dependency is missing. However, you don't have to download the JAR files yourself—that's what Gradle is for. You just need to add the dependency to your build script; the README of RichTextFX provides an example1.

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.fxmisc.richtext:richtextfx:0.9.2'
}

Gradle will pull in all the needed dependencies for you. For more information, see Introduction to Dependency Management.

Note that doing it this way you shouldn't have to declare a library in IntelliJ. If your project is setup as a Gradle project then IntelliJ will see the dependencies declared in your build script(s) and add them to the project. You may have to "import changes" after modifying the build script. These help pages provide more information.


1. The example uses compile but Gradle recommends implementation—at least for the more recent versions (compile is deprecated). Note that Android projects may still use compile, though I'm not sure.

Slaw
  • 37,820
  • 8
  • 53
  • 80
  • Thank you so much, I got it to work! Quick follow up question, should the other libraries I added be moved to gradle? Would this be considered better style? – Maxwell Norfolk Feb 24 '19 at 00:53
  • All dependencies should be declared in Gradle. Note that Gradle is not just a dependency management tool but a full blown build tool; it needs to know the dependencies in order compile and test your project. Where possible you should also delegate build tasks to Gradle rather than using IntelliJ (or other IDE) directly. You'd still use the IDE but the IDE should be using Gradle "behind the scenes". Also, if you have a dependency not available in a repository, such as Maven Central, see [this question](https://stackoverflow.com/questions/20700053/). – Slaw Feb 24 '19 at 01:12
  • And if you have a dependency on another [subproject](https://guides.gradle.org/creating-multi-project-builds/), see [this question](https://stackoverflow.com/questions/25030101/) and/or [this question](https://stackoverflow.com/questions/13595610/). – Slaw Feb 24 '19 at 01:15