aspose file tools*
The moose likes Java in General and the fly likes Jar Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Jar Problem" Watch "Jar Problem" New topic
Author

Jar Problem

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 618
I have created a jar file with this command :

D:\jar\FinalSchool>jar cmf0 Manifest.txt SchoolFinal2.jar *
Where,
D:\jar\FinalSchool is the directory where class files package, and manifest file exists.

After this command a jar is created in FinalSchool package. If i run the jar by double-clicking it, it runs fine. But, if i copy this created jar to another location, it doesn't works.

It shows the following exception :



But, i have included the jcalendar-1.4. And this program works fine when located in the place where it was created


kunal
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 618
After little bit research i found that, when placing all required jars with the jar created in a separate folder, it works.
Now my Question is that, since the created jar contains the required jars, why , again i need to place the required jars with this application jar? And what is the solution for this?

Here is my manifest file :
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 618
No reply yet

Please reply Ranchers
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 367
    
    1

Kunal Lakhani wrote:After little bit research i found that, when placing all required jars with the jar created in a separate folder, it works.
Now my Question is that, since the created jar contains the required jars, why , again i need to place the required jars with this application jar? And what is the solution for this?

Here is my manifest file :


Here, the problem is of classpath.
You are having JARs inside a JAR. So, if you give classpath as '.', JVM will search for classes inside the Jar File (But not inside the JARs inside that JAR)..

If A.jar contains A.class and B.jar
and B.jar contains B.class
Then, with classpath set to '.', and running the A.jar, JVM will be able to find A.class, but not B.class which is inside B.jar

I have found the problem for you, and you have to find the Solution. If you sort out this problem, you are done.

Hint: - You need to use Custom Class Loader (JarClassLoader in this case).. There are other ways also..
For more help, you can use this link.
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 618
thanks for your reply R. Jain. That was a wonderful information. I am looking forward to use Custom Class Loader. Will post the updates here
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 618
After googling i found a solution, that if i create an .exe file and package all required jar files, this problem doesn't occurs. Any negative point with this?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Jar Problem
 
Similar Threads
Error while connecting Applet to database within browser
Persistence.xml file not wokring in JGrasp IDE
null pointer
Populate Array of type Double from text file
Accessing reports gives net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException