This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes Java in General and the fly likes Jar Problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Jar Problem" Watch "Jar Problem" New topic
Author

Jar Problem

Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 609
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: 609
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: 609
No reply yet

Please reply Ranchers
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 276

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.


OCPJP
Kunal Lakhani
Ranch Hand

Joined: Jun 05, 2010
Posts: 609
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: 609
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://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Jar Problem
 
Similar Threads
null pointer
Accessing reports gives net.sf.jasperreports.engine.JRException: java.io.FileNotFoundException
Error while connecting Applet to database within browser
Populate Array of type Double from text file
Persistence.xml file not wokring in JGrasp IDE