• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Project distribution jar file issue.

 
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a project that I want to distribute for testing.

I have netbeans compile the jar file for me, I zip up the dist dir with a simple run.cmd file to kick it off.
This project has an ini file included in the jar file. While in the IDE it runs fine as i have the path to the ini coded in to be found where ever the class is sitting.



So that works correctly with an 'exploded' file structure run from the IDE, but if I run it while compressed in a jar file from the command line it can't find the ini.

If i look at the contents of the jar i see the ini file where it should be. What am i doing wrong? Why can't it find the file?

fyi
The idea behind the ini file is it contains a URL and if it changes I want to just send a new ini file instead of new code.
 
Chuck Barnes
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
upon looking around I found references to .properties files and even xml files to use when saving user settings to the user's home dir via the Properties class

But I don't see the similarity with my issue. my issue is with a static setting that I want to retrieve every time and user can't change it from the app.

Also, I didn't want stray files lying around. I thought that was the point to the jar file. everything in once place.

Also, whether we are talking about an ini file, a .properties file or an xml file. how does java know where to find said file inside the jar file? I would still have the same issue using any one of those file types, correct?
 
Ranch Hand
Posts: 164
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you need to make a manifest file with the jar file, I could be wrong though. I usually don't include external resources like images and configuration files in my jar file
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chuck Barnes wrote:Also, whether we are talking about an ini file, a .properties file or an xml file. how does java know where to find said file inside the jar file? I would still have the same issue using any one of those file types, correct?



It doesn't, of course. You have to tell it by writing suitable code.

But the code you posted originally used a FileInputStream, which can't work because a resource inside a jar isn't a file. If I interpret what you posted there, it looks like the "setting.ini" file is in the same folder as the class named "read" inside the jar. In that case the code you want is this:


And yes, the last part of the file name has no effect on that.
 
Chuck Barnes
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Unnar Björnsson wrote:I think you need to make a manifest file with the jar file, I could be wrong though. I usually don't include external resources like images and configuration files in my jar file



What do you do with them? How do you package it along with the jar?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The purpose of the manifest is to identify where to find things which are outside the jar, at least that's what the Class-Path entry is for. Your problem is the opposite, namely how to find things which are inside the jar.
 
Chuck Barnes
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Paul Clapham wrote:

Chuck Barnes wrote:Also, whether we are talking about an ini file, a .properties file or an xml file. how does java know where to find said file inside the jar file? I would still have the same issue using any one of those file types, correct?



It doesn't, of course. You have to tell it by writing suitable code.

But the code you posted originally used a FileInputStream, which can't work because a resource inside a jar isn't a file. If I interpret what you posted there, it looks like the "setting.ini" file is in the same folder as the class named "read" inside the jar. In that case the code you want is this:


And yes, the last part of the file name has no effect on that.



Yes you are correct. that worked! Wonderful, thanks for the help

....but, i think I don't want to do it that way either..... LMAO. After I thought it about some more, I asked myself, do I really want to be sending out the jar file if only the settings file changes? well no... I only want to send the ini file itself and overwrite the old one.
That is the least amount of steps.

So i think i want it external to the jar, so is that where the manifest comes into play? how is that done? Is it something I can tell the IDE to construct? ie tell it to include the ini file in the dist folder, and in turn the manifest file would reflect that relative path? or is it a manual process?

at least I will know how to package things both in and outside of jars.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Chuck Barnes wrote:After I thought it about some more, I asked myself, do I really want to be sending out the jar file if only the settings file changes? well no... I only want to send the ini file itself and overwrite the old one.


On the other hand if you're distributing the jar file via JNLP then generating a new jar is by far the simplest way to do it, even if there's only one trivial change in the new jar.

And if you're distributing the jar by e-mailing it to your friends, or some similar process, then sending a new version of the jar is again the simplest way to do it. Otherwise you're going to need an installer which puts the jar and all of the pieces into the right place the first time, and a patcher which puts the revised pieces into the right place the next time.
 
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic