简体   繁体   中英

ClassNotFoundException after JAR is exported

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 ZD4365F262EFB00844DDCE05B80 DE0722Z.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>

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+.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM