I am getting a "no class definition found" exception while trying to run my application on Windows (it runs fine on OS X). The classes the JVM is complaining about are my classes (no third party jars required). When I unzip the files inside the jar, all files are present, including the ones the JVMm is complaining about.
The jar is created using the following task:
<target name="jar" depends="">
<jar destfile="build/app.jar" >
<manifest>
<attribute name="Built-By" value="hamza"/>
<attribute name="Main-Class" value="com.hamza.driver.ui"/>
<attribute name="Class-Path" value="./"/>
</manifest>
<fileset dir="build">
<include name="**/*.class"/>
<include name="**/*.png"/>
<include name="**/*.xpi"/>
<include name="**/*.html"/>
<exclude name="**/*.jar"/>
</fileset>
</jar>
I cannot figure out what is causing the problem. If I unzip the jar and run the jar from the directory I unzipped the class to, everything works fine. So, I am assuming all the required files are inside the jar.
EDIT: com.hamza.driver.ui
is a class in a package called com.hamza.driver
which has main
.
After the build, I get one jar "app.jar", and I run it using "java -jar app.jar", which executes fine on OS X, but not on Windows.
If I unzip app.jar
in a seperate directory and run "java -jar app.jar", it excutes fine.
EDIT 2: exception:
Exception in thread "main" java.lang.NoClassDefFoundError: com/hamza/gui/tr ansfer/ClipboardTransferHandle at com.hamza.driver.ui.main(Unknown Source) Caused by: java.lang.ClassNotFoundException: com.hamza.gui.transfer.Clipboa rdTransferHandle at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) 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) at java.lang.ClassLoader.loadClassInternal(Unknown Source) ... 1 more
ClipboardTransferHandle .class files are present in the jar.
EDIT 3: imports for the clip board class:
import java.util.logging.Logger; import java.awt.datatransfer.Clipboard; import java.awt.datatransfer.ClipboardOwner; import java.awt.datatransfer.Transferable; import java.awt.datatransfer.StringSelection; import java.awt.datatransfer.DataFlavor; import java.awt.datatransfer.UnsupportedFlavorException; import java.awt.Toolkit; import java.io.IOException;
While playing with it, I found that if I try to declare ClipboardTransferHandle
as a static variable in the driver, it works, but every object that is not static is not found.
All the main GUI elements are static variables, so the GUI is constructed, but other elements are not; everything that is created not static causes NoClassDefFound
, but if I declare them static for testing, they work.