Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JAR Tool : Not encapsulating the images

 
Shyam Prasad Murarka
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Readers,
I have three directories as follows:
  • source
  • classes
  • images


  • I give the following command at the Command Prompt from inside the classes folder:

    jar cvfm Minesweeper.jar manifest.mft *.class ../source ../images

    Note: THe manifest file is inside the classes folder itself.

    The required jar file is created and when I double-click the jar file the application starts and the program runs perfectly.

    Now I cut-and-paste the jar file to some other directory. When I double-click the jar file and run it the program still runs EXCEPT for the images which DO NOT get displayed!! And I checked up and found that the relative path of the files is NOT DISTURBED. If I try executing it from the original location THEN the program runs along with the images.

    I seriously can't understand why this is happening. I thought that files were encapsulated inside the jar file. I spend hours trying everything: from MODIFYING the manifest file to CREATING the jar files from different locations.

    I then took some time off and read JAR tutorial trail from Sun's Tutorial but in vain.

    I looked up some jar files from jdk1.5 sample code and copied and pasted one of them into another location. And lo and behold it worked perfectly along with the displaying of images. Its utter discrimination by Sun against me!! JUST KIDDING!!

    But I would appreciate it if anyone could pull me out of this mess!!
     
    Shyam Prasad Murarka
    Ranch Hand
    Posts: 209
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Dear Readers,
    Dosen't anyone have any ideas at all?? ANY idea please!!
     
    Rusty Shackleford
    Ranch Hand
    Posts: 490
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I do not know for sure. I am not very good at the nuances of jar files.

    Try taking the manifest file out of classes and put it up one level, and change the path to images. If that doesn't work, I dunno. Hopefully someone more knowlegeble can correct me.
     
    Tony Morris
    Ranch Hand
    Posts: 1608
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You are probably referring to your images as relative file paths (relative to System.getProperty("user.dir"). Instead, load your images using the class loader (ClassLoader.getResourceAsStream).
     
    Shyam Prasad Murarka
    Ranch Hand
    Posts: 209
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Dear Tony,
    Do you think you could explain the ClassLoader in a bit more detail by giving a small example. Or a link where they teach us the usage of ClassLoader.
    And i have been loading my images by creating ImageIcon and then displaying it.
     
    Shyam Prasad Murarka
    Ranch Hand
    Posts: 209
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Dear Readers,
    Thanks a lot. I read the article. I will try it out soon enough and let you'll know whether it worked.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic