Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Question] Cannot find local jar class after maven package #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
Meltryllis163 opened this issue May 4, 2025 · 1 comment
Open

[Question] Cannot find local jar class after maven package #467

Meltryllis163 opened this issue May 4, 2025 · 1 comment

Comments

@Meltryllis163
Copy link

Summary:
When I run the package exe file with local jar, I get exception info below (My system is Microsoft Windows
Version24H2 26100.3775)

E:\CodeProjects\Java\NovelFormatterFX\target\NovelFormatter>NovelFormatter.exe
May 04, 2025 5:45:12 PM com.sun.javafx.application.PlatformImpl startup
警告: Unsupported JavaFX configuration: classes were loaded from 'unnamed module @2928854b'
Exception in Application start method
Exception in thread "main" java.lang.RuntimeException: Exception in Application start method
        at com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:893)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:196)
        at java.base/java.lang.Thread.run(Unknown Source)

// Here is my question
Caused by: java.lang.NoClassDefFoundError: xss/it/nfx/NfxWindow
        at cc.meltryllis.nf.ui.MainApplication.start(MainApplication.java:45)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:839)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:483)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:456)
        at java.base/java.security.AccessController.doPrivileged(Unknown Source)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:455)
        at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
        at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
        at com.sun.glass.ui.win.WinApplication.lambda$runLoop$3(WinApplication.java:184)
        ... 1 more
Caused by: java.lang.ClassNotFoundException: xss.it.nfx.NfxWindow
        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)
        ... 10 more

Detail:
I want to import a local jar nfx-core-1.0.2.jar to my maven project.
Here is my pom.xml:

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>cc.meltryllis</groupId>
    <artifactId>NovelFormatterFX</artifactId>
    <version>1.2.1</version>
    <name>NovelFormatter</name>
    <description>JavaFX Novel Formatter.</description>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <junit.version>5.10.2</junit.version>
    </properties>

    <dependencies>
        ......
        <dependency>
            <groupId>xss.it.nfx</groupId>
            <artifactId>nfx-core</artifactId>
            <version>1.0.2</version>
            <scope>system</scope>
            <systemPath>${project.basedir}/libs/nfx-core-1.0.2.jar</systemPath>
        </dependency>
    </dependencies>

    <build>
        ......
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.13.0</version>
                <configuration>
                    <source>21</source>
                    <target>21</target>
                    <annotationProcessorPaths>
                        <!-- 这里必须声明lombok,否则编译时lombok会无效 -->
                        <path>
                            <groupId>org.projectLombok</groupId>
                            <artifactId>lombok</artifactId>
                            <version>1.18.36</version>
                        </path>
                    </annotationProcessorPaths>
                    <compilerArguments>
                        <extdirs>${project.basedir}/libs</extdirs>
                    </compilerArguments>
                </configuration>
            </plugin>
            <plugin>
                <groupId>io.github.fvarrui</groupId>
                <artifactId>javapackager</artifactId>
                <version>1.7.6</version>
                <executions>
                    <execution>
                        <phase>package</phase>
                        <goals>
                            <goal>package</goal>
                        </goals>
                        <configuration>
                            <!-- 必须 -->
                            <mainClass>cc.meltryllis.nf.Main</mainClass>
                            <!-- 可选 -->
                            <bundleJre>true</bundleJre>
                            <generateInstaller>false</generateInstaller>
                            <url>https://github.com/Meltryllis163/NovelFormatterFX</url>
                            <licenseFile>${basedir}/LICENSE</licenseFile>
                            <winConfig>
                                <copyright>Github@Meltryllis163</copyright>
                                <generateSetup>false</generateSetup>
                                <generateMsi>false</generateMsi>
                                <generateMsm>false</generateMsm>
                                <fileVersion>${project.version}.0</fileVersion>
                                <productVersion>${project.version}.0</productVersion>
                                <!-- 用于开启控制台,然后在CMD窗口中输入NovelFormatter.exe,运行EXE程序来查看控制台 -->
                                <headerType>console</headerType>
                            </winConfig>
                            <additionalModules>
                                <!-- 详见 https://github.com/fvarrui/JavaPackager/issues/429 -->
                                <additionalModule>java.naming</additionalModule>
                                <!-- 否则找不到GBK2312字符集 -->
                                <additionalModule>jdk.charsets</additionalModule>
                            </additionalModules>
                            <additionalResources>
                                <additionalResource>${project.basedir}/libs</additionalResource>
                            </additionalResources>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.openjfx</groupId>
                <artifactId>javafx-maven-plugin</artifactId>
                <version>0.0.8</version>
                <configuration>
                    <!-- 格式:模块/主类 -->
                    <mainClass>cc.meltryllis.nf/cc.meltryllis.nf.Main</mainClass>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

Some situations I tried:

  • If I run it in IDEA, the program is fine. But if I package and then run exe, it can't find nfx-core.jar.
  • You can get the complete project from the package-test branch
@Meltryllis163
Copy link
Author

I have achieved my goal by installing this jar into my local maven repository, so this problem is not urgent :) I just want to know why the above method does not work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant