• 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

Property Files inside Jar File

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I got a problem..I have put some application specific property files inside a package and bundled as a jar file.

The problem is everytime I have to unjar-edit property files-jar and install in a specific environment. I have got something like port,mode etc..to be configured for my application.

Is there any other way I can go abt this issue? I have 2 proprty files in my application.
 
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does the JAR include some code as well? Even if it doesn't, you can use the behaviour of ClassLoaders to hide the fact that the data is zipped.

It easiest when there is a class in the jar eg MyClass, then you can use

Where 'location' will be something like "/com/javaranch/davo/my.properties", ie relative to the JAR root.

It's a bit more involved if you don' have a class to 'attach' to, or the current class can't 'see' the class in the JAR, but you can create a URLClassLoader, pass the URL of the jar, then load the properies from you Classloader instance in the same way. This would be something best hidden behind a 'properties managing class'.

Hope this helps.
Dave.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
oops, almost forgot:

"Shanmuga",
Your display name does not comply with the Javaranch Display name rules. You can check out the rules here.

We require your display name to be two words: your first name, a space, then your last name. Obviously fictitious names are not allowed.

You can edit your display name here.

Thanks,
Dave.
[ June 14, 2004: Message edited by: David O'Meara ]
 
Shanmuga Raja
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response Dave..

Yes I do have some class files also inside the jar.

Actually I want my users to just edit the plain property file to put in Port, Mode etc.. I am just fine with loading property file but how to make it avilable for the users where I am going to install my application.coz If I make it as a jar file they have to unjar to put their property values.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for changing your display name, I appreciate it

There are a nmber of ways to do this, but you start to run into hard-coded locations or assumptions on the location of files. Depending on how you deploy your application, you may be able to use the ClassLoader to find the location of the JAR containing the source, then assume the properties file is in the same directory.

Hint: turn the class name into a file eg /com/mypackage/MyClass.class, use the ClassLoader to get the URL, use the URL to find the file, use the file to find the directory.

I'm not sure it's an elegant solution, maybe someone else has an opinion.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic