This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes ResourceBundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "ResourceBundle" Watch "ResourceBundle" New topic
Author

ResourceBundle

Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
hi guys,

I m compressing files in JAR but the problem is that I had created configuration file for my customers for the purpose of making changes according to their needs and the saw will be reflected when they will run the program. But the thing is in JAR file i had placed the config file on its root and suppose if client want to make some changes then it will have to use java commands on its console for updating the jar file which i dont want. have a look at my code and suggest how is it possible for me to set the configuration file such that they can change the matter and without updating jar file they can see the changes in program. Or do I need to capture the configuartion file to my main program and allow the client to make changes thier and save it. Shall i go this way ?. Advice .

static
{
try
{
resources = ResourceBundle.getBundle("configuration");
SwingUtilities.invokeAndWait(progress);
}

catch (MissingResourceException mre)
{
JOptionPane.showMessageDialog(null, "Configuration file is missing from its path !!! Re-install in its path",
"Configuration Missing", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}

catch (Exception e)
{
JOptionPane.showMessageDialog(null, "Thread was Interrupted UNEXPECTED !!!" + e,
"Interrupted", JOptionPane.ERROR_MESSAGE);
System.exit(0);
}

}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41151
    
  45
Two ideas:

1) On the first startup, copy the config file to the users home directory as an invisible file, and work off of that. That way it's changeable. Although, come to think of it, I don't think it's possible to make it invisible on Windows.

2) You might try updating the jar file itself programmatically using the java.util.jar package. I'm not certain that it's possible to update a single file in it, though, but might be worth a try. Of course, with the program running, the jar file might be open, and thus not accessible for changes.


Ping & DNS - my free Android networking tools app
Gurpreet Saini
Ranch Hand

Joined: Jun 09, 2002
Posts: 295
hi,

I had worked on ur second opinion. I have succeded in getting the text file on my JtextPane component and I had also inserted Save button but now i want this file to be updated on ce the user clicks save button. I want to update only this file. Whats the way out ?.

Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41151
    
  45
Where are you stuck? You have an ActionListener on the button which grabs the text using JTextPane.getText(). Now you need to open the Jar file and update the config file (assuming that's possible, which -like I said above- I don't know).
Check out the JarFile class to do that. Looking at the API it would seem that you need to read the complete file, and write a new copy, during which you replace the old config file with the new one. But that's just my reading of the javadocs, because I didn't notice methods to update one of its entries in place.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: ResourceBundle
 
Similar Threads
JDBC not included into jar file?
JasperREport not working in .jar file
Catch Exceptions With Appropriate Ways
Having Problems with Opening a file...
indexOf() error