返回

线程“JavaFX 应用程序线程”中的 JavaFx 异常 线程“主”java.lang.NoClassDefFoundError 中的异常:org/apache/log4j/Logger

发布时间:2022-07-15 07:38:54 233
# 移动端

该应用程序在 Eclipse 和 IntelliJ 以及“ant run”中运行得非常好。只有当我以 Windows cmd 运行时才会出现以下错误:

java -jar TheApp.jar

    Exception in thread "JavaFX Application Thread" Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logger
        at com.th.app.ui.Login.(Unknown Source)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Unknown Source)
        at com.sun.javafx.application.LauncherImpl.lambda$launchApplicationWithArgs$2(LauncherImpl.java:352)
        at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$7(PlatformImpl.java:326)
        at com.sun.javafx.application.PlatformImpl.lambda$null$5(PlatformImpl.java:295)
        at java.security.AccessController.doPrivileged(Native Method)
        at com.sun.javafx.application.PlatformImpl.lambda$runLater$6(PlatformImpl.java:294)
        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$null$4(WinApplication.java:185)
        at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
        at java.net.URLClassLoader.findClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
        at java.lang.ClassLoader.loadClass(Unknown Source)
        ... 12 more
java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
        at java.lang.reflect.Method.invoke(Unknown Source)
        at sun.launcher.LauncherHelper$FXHelper.main(Unknown Source)
Caused by: java.lang.NullPointerException
        at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:383)
        at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
        ... 5 more

这似乎是一个 -classpath 问题,但我已经花了一天多的时间,但仍然得到同样的错误。

我正在附加 build.xml,它也可以完美运行:

<?xml version="1.0"?>

<project name="App" default="all" basedir=".">

    <property name="src"   value="./src"/>

    <property name="build" value="./build"/>

    <property name="lib"   value="./lib"/>

    <property name="dest"   value="./dest"/>

    <property name="main-class"  value="com.th.app.ui.Login"/>

    <path id="classpath">

        <fileset dir="${lib}" includes="**/*.jar"/>

    </path>

    <target name="all" depends="clean, compile, jar, copy-file" description="Builds the whole project">

        <echo>Doing all</echo>

    </target>

    <target name="clean" description="Removes previous build">

        <delete verbose="true">

            <fileset dir="${build}"/>

        </delete>

    </target>

    <target name="compile" depends="clean" description="compile whole project">

        <echo>compile ${ant.project.name} </echo>

        <mkdir dir="${build}/classes"/>

        <copy file="./config.properties" tofile="${build}/classes/config.properties"/>

        <copy file="./src/log4j.properties" tofile="${build}/classes/log4j.properties"/>

        <copy todir="${build}/classes/com/th/app/ui">

           <fileset dir="${src}/com/th/app/ui">

                   <include name="**/*.fxml"/>

                   <include name="**/*.css"/>

           </fileset>

        </copy>

        <javac srcdir="${src}" destdir="${build}/classes" classpathref="classpath" includeantruntime="false" />

    </target>

    <target name="jar" depends="compile">

        <mkdir dir="${build}/jar"/>

        <jar destfile="${build}/jar/${ant.project.name}.jar" basedir="${build}/classes">

            <manifest>

                <attribute name="Main-Class" value="${main-class}"/>

            </manifest>

        </jar>

    </target>

    <property name="args" value="READWRITE"/>

    <target name="run" depends="copy-file, input-runargs">

        <java fork="true" classname="${main-class}">

            <classpath>

                <path refid="classpath"/>

                <path location="${dest}/jar/${ant.project.name}.jar"/>

            </classpath>

            <arg line="${args}"/>

        </java>

    </target>

    <target name="input-runargs" unless="args" description="prompts for command line arguments if necessary">

       <input addProperty="args" message="Type the desired command line arguments:"/>

    </target>

    <target name="copy-file">

        <copy todir="${dest}"><fileset dir="${build}"/></copy>

    </target>

</project>

这是我的第一个 JavaFx 项目,我正在努力完成它。

请提供帮助,非常感谢任何见解。

特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报
评论区(1)
按点赞数排序
用户头像