I am having trouble correctly generating a Jar for my Java implementation. I am not a Java master ( Thus why I am using Make and not Ant). I didn’t think I cared about a Jar until I realized my Windows machine didn’t hava javac. Then I thought to myself “If only I had a jar”
So I hacked a few lines together in a Makefile trying
The relevant lines are
all: client server jar
client: bin bin/Job.class bin/JobQueue.class bin/Client.class bin/FileTransfer.class
server: bin bin/Job.class bin/JobQueue.class bin/Server.class bin/ServerThread.class bin/FileTransfer.class
jar: client server
jar cfe HBNQServer Server bin/Server.class bin/Job.class bin/JobQueue.class bin/ServerThread.class bin/FileTransfer.class
jar cfe HBNQClient Client bin/Client.class bin/Job.class bin/JobQueue.class bin/FileTransfer.class
However when I attempt to run it I get a No Class Found Exception.
$ java -jar HBNQServer
Exception in thread "main" java.lang.NoClassDefFoundError: Server
Caused by: java.lang.ClassNotFoundException: Server
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
I am sure the mistake is painfully obvious to anyone more familiar with “Jaring” files.
If I left any important code out, it may be found Here
I believe your problem is the
binprefix. If you jar a class file, it must be in a directory identical to its fully qualified package name. For example, if you implement acom.mycompany.Serverclass, the corresponding path in the jar file must becom/mycompany/Server.class. In your case, everything is in thebindirectory in the jar file, so it can’t find your (presumably un-package-qualified) classes. Either put all of your classes in thebinpackage, or jar them up without thebinprefix.Something like this might work: