• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

executable jar file

 
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
While creating the above , I came upon this issue of what someone like me who had downloaded jdk 1.4.0_01 and renames it as jdk1.4 on his/her machine. In that case when one creates jar file one may end up setting up something like this
manifest file 1
Manifest-Version: 1.0
Created-By: 1.4 (Sun Microsystems Inc.)
Main-Class: suncertify.client.FBNTable
instead of
manifest file 2
Manifest-Version: 1.0
Created-By: 1.4.0_01 (Sun Microsystems Inc.)
Main-Class: suncertify.client.FBNTable
in that case when you try to execute the jar file using manifest file 1 then you get an error
so is there a way to avoid this ? How do we ensure that the examiner has modified the environment file or other files with the right values ? Do we explicitly ask the examiner to modify the manifest file with appropriate version of jdk on his machine ?
Thanks
Ravi
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ravi, is this for the Beta exam?
If it isn't, I'd suggest going back to SDK 1.3. And keep the defaults of the installation.
Mark
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mark,
I have a problem to read a image file from a jar file. I have jar all image files under images folder, which is under root, into client.jar. By using:
java -jar client.jar
My application failed to load the images. Here is the code for the image: new ImageIcon("images/exit.gif")
I tried to find if there is header-value needed in Manifest file, Could not find any infomation about this.
Could you or anybody give me some hints about this? Thanks,
Patrick
 
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Patrick,
You have to load stuff in a jar as a resource and not a file. Here's what you need to do:

Hope this helps,
Michael Morris
 
Patrick Li
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Michael.
Your solution: this.getClass().getResource("/images/exit.gif") solved my problem rightway.
does this imply that I could load db.db (default) file from a jar file directly when the users do not provide a path (name) for database file name?
same to other text and properties files, are we supposed to always use getClass().getResourceAsStream or getResource to load the file rather than a file name (System.getProperty("user.dir") + System.getProperty("file.separator")+ filename)? or does this only imply to a jar?
Thanks,
Patrick
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Patrick,


does this imply that I could load db.db (default) file from a jar file directly when the users do not provide a path (name) for database file name?


You can load it, but you can't save it back to the same jar that your application is started from. At least I don't know of a way to do it.


... same to other text and properties files, are we supposed to always use getClass().getResourceAsStream or getResource to load the file rather than a file name (System.getProperty("user.dir") + System.getProperty("file.separator")+ filename)? or does this only imply to a jar?


Only to jar files. You can certainly put property files, etc. in your jar and load them as resources but with the same caveat as above: they are read-only.
Hope this helps,
Michael Morris
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic