Please forgive the seemingly simple question, but i have run into a brick wall over this. I have RTFM, RTFT and STFW & I am stuck.
I am doing a simple Hellowrld app, within a package. Now I can get it to comile without issue with Ant, I can even create a .jar file, but I cannot get it to run.
When I "java -jar HelloWorld.jar", I get the following error.
Exception in thread "main" java.util.zip.ZipException: The system cannot find the file specified at java.util.zip.ZipFile.open(Native Method) at java.util.zip.ZipFile.<init>(ZipFile.java:112) at java.util.jar.JarFile.<init>(JarFile.java:127) at java.util.jar.JarFile.<init>(JarFile.java:65)
From the link you sent me, this looks like there is something missing - a reference to the main class? (in this case HelloWorld) If that is the case, how do I get the requried information into the manifest file?
Thanks for the help so far,
posted 14 years ago
Craig, I assume that one of the classes in your jar file has a main() method in it? The link I gave you in the post above shows how to create an executable jar file.
Assuming that your jar file is in the correct format and order, you can create a manifest file under the WEB-INF directory (call it manifest.mf to keep this simple). In manifest.mf put the following:
This assumes that the name of the source file containing the main() method is Hello.java and the name of the resultant classfile is Hello.class. Then create the executable jar file as usual. This should work, but if it doesn't you will have to look into the build file or possibly do this manually with the following command:
jar cmf WEB-INF/manifest.mf <jar-file> <input-files>
the <jar-file> is a marker for whatevery you are calling the jar file and the <input-files> include the class files going into the jar.
I tend to disagree with your decision, as in the original post I made reference to using ant, and included the build.xml file. I am still trying to determine how to do this with Ant, so if anyone knows how to get thsi to work, I'll appreciate it alot.
posted 14 years ago
G'Day Don, Problem solved. There were two(2) issues. 1) typo HellowWorld != HelloWorld 2) Main-Class in the manifest needed to have the package hierarchy included ie Main-Class: path.to.class.HelloWorld
Thanks for helping me to understand the basics!
Also, I found out how to do up the jar task in Ant to do it!