4

I would like to get an image from JAR library to my project.

    <graphic>
        <ImageView>
            <Image url="@/toolbarButtonGraphics/general/TipOfTheDay24.gif"/>
        </ImageView>
    </graphic>

I've added the library to my module and it seemed to be correct but the compiler throws an error: Error occurred during initialization of boot layer java.lang.module.FindException: Unable to derive module descriptor for filepath.jar Caused by: java.lang.IllegalArgumentException: jlfgr.1.0: Invalid module name: '1' is not a Java identifier. Here's my module-info file:

requires javafx.fxml;
requires javafx.controls;

opens sample;
Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
  • 3
    So you have your modular app, and you add a dependency (the jar with the image)? This jar is `jlfgr.1.0.jar`? Why don't you add the jar to the module info? Have you tried renaming it to `jlfgr-1.0.jar`? – José Pereda Apr 24 '19 at 12:37
  • Adding to the module-info after renaming a file helped :) Thank you so much. –  Apr 24 '19 at 13:04
  • Does this answer your question? [Unable to derive module descriptor for auto generated module names in Java 9?](https://stackoverflow.com/questions/46501388/unable-to-derive-module-descriptor-for-auto-generated-module-names-in-java-9) – Naman Sep 30 '20 at 14:07

3 Answers3

5

it seems like you did not follow the steps properly. When you add a new library, first, you add it to your module and then you have to add it to you module-info file.

Just add a line in module-info ---> requires <package-name>;

e.g my package name is graphics-looks.jar ---> requires graphics-looks;

P.S. before adding that jar anywhere, try to rename it and give a simple name by removing numbers and other characters from its name.

Tarun Dadlani
  • 152
  • 3
  • 10
  • 2
    I faced the same issue mentioned above and this solution worked for me. Having numbers and special characters in my jar file was not allowing to add in the module-info file as it is. had to rename the jar file and use. – sher17 Feb 23 '21 at 20:54
  • 1
    Package name having numbers and special character made it difficult to add it to the module-info. To make it clear, what worked for me is getting rid of the numbers and the special characters. Example: renaming jlfgr-1_0 to jlfgr – Anav Katwal May 29 '21 at 14:56
0

Switch the project programming language, set it to version 11 on both sdk and language level. it worked for me.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Mike
  • 1
0

According to Tarun Dadlani Answer.

Firstly, you need to add the .jar file to Modules as the pictures shown. Add .jar file to modules

Secondly, you need to add a new lib to module-info file as the pictures shown. Add a new lib to module-info file

Finally, Rename the .jar file to give a simple name.