on 01-19-2008 4:22 PM
Hello,
I have implemented this class:
public class Conenctor {
private static final String USER = "Administrator";
private static final String PASSWORD = "*******";
private static final String SAP_NAMING_PROVIDER_URL = "vm-sapnwce:50004";
private static final String SAP_INITIAL_CONTEXT_FACTORY_IMPL = om.sap.engine.services.jndi.InitialContextFactoryImpl";
public void connect() {
Properties ctxProp = new Properties();
ctxProp.put(Context.INITIAL_CONTEXT_FACTORY,
SAP_INITIAL_CONTEXT_FACTORY_IMPL);
ctxProp.put(Context.PROVIDER_URL, SAP_NAMING_PROVIDER_URL);
ctxProp.put(Context.SECURITY_PRINCIPAL, USER);
ctxProp.put(Context.SECURITY_CREDENTIALS, PASSWORD);
/*
Create a JNDI API InitialContext object.
*/
Context jndiContext = null;
try {
jndiContext = new InitialContext(ctxProp);
} catch (NamingException e) {
System.out.println("Could not create JNDI API" + "context: "
+ e.toString());
e.printStackTrace();
}
...
}
...
}
Now my question:
The properties
private static final String USER = "Administrator";
private static final String PASSWORD = "*******";
private static final String SAP_NAMING_PROVIDER_URL = "vm-sapnwce:50004";
are set fix here.
In a productive development you can't set the properties fix because the properties would be different for several customers.
How would this be implemented in a productive development?
Regards,
Armin
Hello Armin,
you could either create a property file, which you could read at the start of the application, where the information is stored in, or you could put the properties into your vm arguments like:
java
-Xmx256m -Dctx_user=Administrator -Dctx_password=***** and so on
<main_class>
All arguments which start with -D are loaded in to System-property table. You could use freely selected names for you arguments, but be careful, not to use already forgiven names.
To read this information use this code:
String ctx_user = System.getProperty("ctx_user");
To read a property file with this content:
ctx_user=Administrator
ctx_password=*****
you could use this code:
Properties properties = new Properties(),
properties.load(new FileInputStream(new File(<property file>));
String ctx_user = properties.getProperty("ctx_user");
Greetz
Volker
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
89 | |
10 | |
9 | |
9 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.