Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Jar Problem

 
Kunal Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 Lakhani
Ranch Hand
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No reply yet

Please reply Ranchers
 
R. Jain
Ranch Hand
Posts: 375
1
Java Python Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 622
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic