Home > front end >  Successfully runs in Eclipse IDE but shows errors after built in Maven
Successfully runs in Eclipse IDE but shows errors after built in Maven

Time:08-19

Runs good in IDE

Builds good in MAVEN

This program runs well in IDE (as in picture). I built the project and the build is successful too. i built some more programs from maven and they all work. But when I try to open the shaded jar file, it gives the error which i have placed below.:

Exception in Application start method Exception in thread "JavaFX Application Thread" java.lang.NoClassDefFoundError: com/sun/javafx/scene/control/skin/ButtonSkin
    at io.github.palexdev.materialfx.controls.MFXButton.createDefaultSkin(MFXButton.java:351)
    at javafx.scene.control.Control.doProcessCSS(Control.java:897)Caused by: java.lang.ClassNotFoundException: com.sun.javafx.scene.control.skin.ButtonSkin
    ... 21 moreException in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/scene/control/skin/ButtonSkin
    at java.base/java.lang.ClassLoader.defineClass1(Native Method)
    at java.base/java.lang.ClassLoader.defineClass(ClassLoader.java:1013)
    at java.base/java.security.SecureClassLoader.defineClass(SecureClassLoader.java:150)
    at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:862)
    at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
     Caused by: java.lang.ClassNotFoundException: com.sun.javafx.scene.control.skin.ButtonSkin
    ... 21 more
     Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
    at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:833)
    Caused by: java.lang.NoClassDefFoundError: com/sun/javafx/scene/control/skin/ButtonSkin
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:174)
    ... 1 more
    Caused by: java.lang.ClassNotFoundException:com.sun.javafx.scene.control.skin.ButtonSkin
    ajava.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
    ... 48 more     

Folder structure : danielproject

   ├───src
   │   ├───main
   │       ├───java
   │       │   ├───com
   │   │   │   │   └───prajan
   │   │   │   │       └───danielproject
   │   │   │   └───DBConnection
   │   │   └───resources
   │   │       └───danielproject
   │   

POM file:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.prajan</groupId>
<artifactId>danielproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
     <dependency>
        <groupId>org.glavo.materialfx</groupId>
        <artifactId>materialfx</artifactId>
        <version>11.13.5</version>
    </dependency>
    <dependency>
          <groupId>mysql</groupId>
         <artifactId>mysql-connector-java</artifactId>
        <version>8.0.28</version>
    </dependency>
   <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-controls</artifactId>
        <version>15.0.1</version>
    </dependency>
    <dependency>
        <groupId>org.openjfx</groupId>
        <artifactId>javafx-fxml</artifactId>
        <version>15.0.1</version>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.0</version>
          <configuration>

                    <source>11</source>

                        <target>11</target>

        </configuration>
        </plugin>

        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
                <execution>
                    <goals>
                        <goal>java</goal>
                    </goals>
                </execution>
            </executions>
            <configuration>
                  <mainClass>com.prajan.danielproject.Launcher</mainClass>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <version>3.0.0</version>
           


            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
                    <configuration>
                    <shadedArtifactAttached>true</shadedArtifactAttached>
                        <transformers>
                            <transformer
                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                               <mainClass>com.prajan.danielproject.Launcher</mainClass>
                            </transformer>
                        </transformers>
                    </configuration>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

</project>

Launcher class:

package com.prajan.danielproject;

public class Launcher {

    public static void main(String[] args) {
        Main.main(args);

    }

}

CodePudding user response:

I used the recent version of dependency and it works outside IDE. Thank you guys for suggesting..

<dependency>
    <groupId>io.github.palexdev</groupId>
    <artifactId>materialfx</artifactId>
    <version>11.14.0-EA3</version>
</dependency>
  • Related