0

I am using JRE 1.9.0 (9.0.4+ 11). I'm trying to create an executable JAR. After I export to JAR with Maven and try to launch it, I get the following error:

Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: com/sun/javafx/css/converters/SizeConverter at org.kordamp.ikonli.javafx.FontIcon$StyleableProperties.(FontIcon.java:265) at org.kordamp.ikonli.javafx.FontIcon.getClassCssMetaData(FontIcon.java:321) at org.kordamp.ikonli.javafx.FontIcon.getCssMetaData(FontIcon.java:325) at javafx.graphics/javafx.scene.CssStyleHelper$CacheContainer.(Unknown Source) at javafx.graphics/javafx.scene.CssStyleHelper$CacheContainer.(Unknown Source) at javafx.graphics/javafx.scene.CssStyleHelper.createStyleHelper(Unknown Source) at javafx.graphics/javafx.scene.Node.reapplyCss(Unknown Source) at javafx.graphics/javafx.scene.Node.reapplyCSS(Unknown Source) at javafx.graphics/javafx.scene.Node.invalidatedScenes(Unknown Source) at javafx.graphics/javafx.scene.Node.setScenes(Unknown Source) at javafx.graphics/javafx.scene.Parent$2.onChanged(Unknown Source)

...

Caused by: java.lang.ClassNotFoundException: com.sun.javafx.css.converters.SizeConverter at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(Unknown Source) at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(Unknown Source) at java.base/java.lang.ClassLoader.loadClass(Unknown Source) ... 103 more

This is happening on the same machine where I exported the JAR from. It works fine when launched from IDE and I suppose my IDE (Eclipse) uses the same JRE as Windows does when launching my JAR since it's the only one I have installed. Libraries I have included with Maven are ikonli 2.3.0 and jfoenix 9.0.8.

I also tried to wrap that same JAR with Launch4J and I ran into the same problem.

Here's build from my pom.xml file

  <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.8.0</version>
        <configuration>
          <release>9</release>
        </configuration>
      </plugin>
            <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-shade-plugin</artifactId>
        <version>3.2.3</version>
        <configuration>
          <transformers>
                <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                    <mainClass>com.project.Main</mainClass>
                </transformer>
             </transformers>
        </configuration>
        <executions>
          <execution>
            <phase>package</phase>
            <goals>
              <goal>shade</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
      <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <archive>
                        <manifest>
                        <addClasspath>true</addClasspath>
                            <mainClass>
                                com.project.Main
                            </mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
    </plugins>
  </build>
lovrodoe
  • 473
  • 8
  • 18
  • 1
    You need to specify the Entry Point while exporting to Runnable JAR File. Entry point is the Java File that contains the main method that you want to execute on running the JAR file. Make sure you export the resources too in the JAR file. – jsgrewal12 May 01 '20 at 10:09
  • 1
    How are you trying to execute it? Did you specify the the external library in the manifest file? – lucsbelt May 01 '20 at 10:13
  • @lucsbelt I don't have manifest file, I'll look into it, thanks. – lovrodoe May 01 '20 at 10:20
  • @jsgrewal12 I have added my build from pom.xml to original post, I do have the entry point. – lovrodoe May 01 '20 at 10:21
  • 1
    Check your manifest file. And these links might help: https://stackoverflow.com/questions/26074463/how-to-create-runnable-jar-with-resources-in-eclipse-from-maven-project , https://javavids.com/video/how-to-create-runnable-jar-file-with-maven – jsgrewal12 May 01 '20 at 10:46
  • 1
    The entry point is clearly not the issue (the errors are generated from trying to apply stylesheets, which it wouldn't be doing if it didn't know which main() method to execute). I don't use jfoenix but this looks like a version problem between the JFX runtime and the JFoenix libraries. – James_D May 01 '20 at 11:54

1 Answers1

1

This does not look at a stylesheet error at all, rather it's probably the use of an incompatible Ikonli version. From the stack trace I gather that the Ikonli version in use is likely lower that 11. JavaFX 9 has binary incompatibilities with certain packages, CSS support for example was moved from private package com.sun.javafx.css to the javafx.css public package.

There are two release branches of Ikonli at the moment, the 2_x branch which is compatible with JavaFX 8 (latest release is 2.6.0), and the main branch compatible with JavaFX 11 and greater (latest release is 11.5.0).

There is no version compatible with Java 9 nor 10. You must either choose Java 8 or Java 11+.

Andres Almiray
  • 3,236
  • 18
  • 28