Problems with .jar files
I have a java application where the file structure is like follows:
--code
-.class files
-images
tat is in the code directory there r .class files and a directory which has the images
now i created a jar as follows from the code directory by
jar mfvc san.txt mfa.jar *.class images
the jar file is created in the same directory code
when i double click on it its running properly
But the problem is when i cut the jar file and paste it an another folder
the images are not coming
y is this happening?
how can we avoid this?
In Windows, when you double click the jar, Windows' File Association uses a form of the command "java -jar ..." to open (run) the jar. When the -jar option is used the only classpath information that Java uses is what is defined by the Class-Path: xxx line in the manifest file.
Apparently your manifest file classpath values are not valid for the new location.
A similar process occures in Solaris, but I don't know the details of that process.
> So cant we make a .jar which can run successfully independently from any
> location?
I can! (Using the methods described in great detail here: http://java.sun.com/docs/books/tutorial/deployment/jar/index.html)
Note: images can fail to appear because of how you specify them. So make sure you have read up on the Class methods getResource() and getResourceAsStream() - there are also ClassLoader methods of the same names, but they don't work exactly the same way.
One gotcha with Windows is that jar entries are cAsE sensitive (while Window's file names are not) so images that were found when an application ran from .class files can fail when it (and its resources) are jarred.
Since all sorts of things can go wrong you may need to post some code - including the contents of the manifest file - and the command with which you launch the application. There is no need to go overboard with the code - just enough to illustrate your problem - a simple JFrame showing an image (or not!) only takes a dozen lines or so of code.