The app runs perfectly fine in Eclipse and IntelliJ, and also in 'ant run'. Only when I run as Windows cmd to get the following errors:
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.<clinit>(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
This appears to be a -classpath problem, but I have spent more than one day but still getting the same error.
I'm attaching the build.xml, which works perfectly also:
<?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>
This is my first JavaFx project and I'm trying hard to get it done.
Please help and any insight is greatly appreciated.