How to get context information in your own class
Hi,
I'm new to Java and I'm trying to create my own class which stores some constants like for example mailServerHost. The class would look something like this:
public class AppSettings {
private static String mailServerHost="localhost";
static{
if(###online-server###)
mailServerHost="another mail server";
}
}
My problem is the if(###online-server###). I don't know how could I find informations about the underlying server.
Is there any way to find out informations about the context(server)?
Thanks,
IMIA
[590 byte] By [
IMIAa] at [2007-11-27 8:08:54]

What do you mean by "if online server"? Do you want to know if the program can access the internet to send mail through a certain server? If so, then you can try to connect, and if you get errors you know you can't access the internet.
Hi,By "if online server" I mean if the application runs on the online server.I just want that when the app runs on the online server some settings get different values compared with the dev-server without taking care all the time when I deploy the app to change the values.
IMIAa at 2007-7-12 19:51:55 >

> Do you still need 韓 this case 2 different
> property-files (one for dev and one for
> online-servers).
Yes, but they would have the same name. ;-)
> After all when you need to load one
> of them you'd still need in your AppSettings class on
> which server your application is running. So I'd
> still need that information.
No, you use a fixed name, e.g. server.properties, for the config file.
You might find class java.util.ResourceBundle interesting.
Thanks for your help. The ideea with the config file "server.properties" it's nice. However, when I need to deploy my app and I use the "Eclipse SDK" to export the application as a .war file won't be the config file "server.properties" overwritten on the server? How do you avoid this?
Thanks!
IMIAa at 2007-7-12 19:51:55 >

Maybe you're looking for the-Dproperty=value
option?
(applied to your dev and prod AppServer)
http://java.sun.com/j2se/1.4.2/docs/tooldocs/windows/java.html
Then you can have config for both dev env and prod env in the config file and just determine which env you are running in from the -D option.
Message was edited by:
tschodt