changes in property file not affecting my exe

I have created a swing application. I have a property file which contains database connection string and other details. i created setup file using Advance Installer where i have packaged jre,jar,lib. inside lib i have a folder called config which has the property file.

after installing and creating exe now i have changed the key value of the property file (ie., ip address where the database resides). if i run the exe it is not reflecting the changes made in property file instead it is retrieving the datas from the database which resides in the old ip address.

whats is the solution for this. its very urgent.

thanks

[647 byte] By [thanua] at [2007-10-3 3:52:21]
# 1

If I understood you correctly you have changed the properties file after creating the exe. That cannot work as the original file is still in the exe. You have to recreate the exe with your new properties file in the config folder.

This is BTW one of the reasons why most users here suggest NOT to use an exe.

PhHeina at 2007-7-14 21:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 2
thanks for ur reply.if not exe what should i use? its a swing stand alone swing applicationthanks
thanua at 2007-7-14 21:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 3

> If I understood you correctly you have changed the

> properties file after creating the exe. That cannot

> work as the original file is still in the exe. You

> have to recreate the exe with your new properties

> file in the config folder.

>

> This is BTW one of the reasons why most users here

> suggest NOT to use an exe.

hai,

i have seen in some product like i-net crystal clear(Reporting tool) if we change the property file

the change is reflected. how could it work for them?.

i dont want to create exe again. the same exe should reflect it. is there anyway to accompolish this

task?

thanks

thanua at 2007-7-14 21:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 4
I'd use a jar or webstart. http://java.sun.com/docs/books/tutorial/deployment/index.html
PhHeina at 2007-7-14 21:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 5

> i have seen in some product like i-net crystal

> clear(Reporting tool) if we change the property file

> the change is reflected. how could it work for

> them?.

>

> i dont want to create exe again. the same exe should

> reflect it. is there anyway to accompolish this

> task?

>

Don't package the properties file inside the exe.

PhHeina at 2007-7-14 21:50:08 > top of Java-index,Desktop,Core GUI APIs...
# 6
oops then how it will work.
thanua at 2007-7-14 21:50:09 > top of Java-index,Desktop,Core GUI APIs...
# 7
How should I know? You`re the Java to exe expert :P
PhHeina at 2007-7-14 21:50:09 > top of Java-index,Desktop,Core GUI APIs...
# 8
expert huh . lols
thanua at 2007-7-14 21:50:09 > top of Java-index,Desktop,Core GUI APIs...
# 9

atlast i found the solution. its simple but since iam a newbie it took time for me to find out. Just create a properties file and store all the info u want in (key,value) pair. then use

FileInputStream to read the values from the properties file.

sample code:

import java.io.*;

import java.util.Properties;

public class PropertiesTest{

public static void main(String[] args){

Properties props=new Properties();

try{

props.load( new FileInputStream(new File("test.properties")));

}catch(IOException ie){

System.out.println("Error reading file");

}

String key = "name";

String val = props.getProperty(key);

System.out.println(val);

}

}

this code works well. even after packaging ur application u can change the contents of the properties file which will be reflected in ur exe cause every time when u run ur exe it reads data from the file. u can save the .properties file in ur classpath or mention the path in which u save.

previously i did a mistake by creating ResourceBundle class and was reading the values from properties file using bundle.getString("Key"). if u use ResourceBundle class it will be packed inside ur jar file so that the changes made to property file after creating exe will not affect it.

check out this link for more info

http://kickjava.com/855.htm

thanua at 2007-7-14 21:50:09 > top of Java-index,Desktop,Core GUI APIs...