Forums Register Login

ResourceBundle

+Pie Number of slices to send: Send
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);
}

}
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
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 ?.

+Pie Number of slices to send: Send
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.
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1168 times.
Similar Threads
Catch Exceptions With Appropriate Ways
indexOf() error
JasperREport not working in .jar file
JDBC not included into jar file?
Having Problems with Opening a file...
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 09:09:33.