aspose file tools*
The moose likes Beginning Java and the fly likes JAR Tool : Not encapsulating the images Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JAR Tool : Not encapsulating the images" Watch "JAR Tool : Not encapsulating the images" New topic
Author

JAR Tool : Not encapsulating the images

Shyam Prasad Murarka
Ranch Hand

Joined: May 02, 2005
Posts: 209
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!!


    With Best Regards,
    Shyam Prasad Murarka
    Shyam Prasad Murarka
    Ranch Hand

    Joined: May 02, 2005
    Posts: 209
    Dear Readers,
    Dosen't anyone have any ideas at all?? ANY idea please!!
    Rusty Shackleford
    Ranch Hand

    Joined: Jan 03, 2006
    Posts: 490
    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.


    "Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
    Tony Morris
    Ranch Hand

    Joined: Sep 24, 2003
    Posts: 1608
    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).


    Tony Morris
    Java Q&A (FAQ, Trivia)
    Shyam Prasad Murarka
    Ranch Hand

    Joined: May 02, 2005
    Posts: 209
    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

    Joined: May 02, 2005
    Posts: 209
    Dear Readers,
    Thanks a lot. I read the article. I will try it out soon enough and let you'll know whether it worked.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: JAR Tool : Not encapsulating the images