This content has been marked as final. Show 6 replies
The last error you posted indicates that the folder MainPackage has not been included in the JAR file. Run
This will include the whole directory, not just the class files in it.
jar -cfm aj.jar MANIFEST.MF MainPackage/
When you use java -jar, the only classpath that is used is the path(s) in the jar manifest Class-Path. In your first scenario, you did not have any Class-Path, that's why the JVM could not find the hcslib.jar jar file.
When you put one or more paths into the Class-Path attribute, the JVM only looks at the specified paths for classes. Since you had only the hcslib.jar in the Class-Path, the JVM could not find MainPackage.AutoGui.
I am fairly certain changing your Class-Path as shown below will work
Class-Path: . C:\jdk\jre\lib\ext\hcslib.jarNotice it is a space, a period and another space before the path to hcslib.jar.
hi , Alexander and atmguy ,
Thank you very much for your reply!
I tried what you suggested but I still got the same errors. Actually, I tried even more for the Class-Path, like put the aj.jar I want to run to the path list, but it did not work.
Anyway, I'll give you each a Duke point.
What happens when you do
jar tf aj.jar
You should see: MainPackage/AutoGui.class
That is, a directory named MainPackage and a class name MainPackage/AutoGui.class
hi atmguy ,
Thank you for your reply again!
Yes. I can see 'MainPackage/AutoGui.class' when I run jar tf aj.jar.
When not packaged, this program works without any problem.
For a program that do not reference external libraries, it works well. For the program that do reference external libraries, it cannot find the library class. However, if I add Class-Path, it can not even find the Main Class.
Does it mean Main-Class and Class-Path attribute can not be be used in the same manifest file?
Hi, Alexander and atmguy,
The problem has been partly resoved by Jos in another thread: