public interface DBConfig extends Constants {
@DefaultStringValue("host")
String host(String host);
@DefaultStringValue("port")
String port(String port);
@DefaultStringValue("username")
String username(String username);
@DefaultStringValue("password")
String password(String password);
}
public void useDBConfig() {
DBConfig constants = GWT.create(DBConfig.class);
Window.alert(constants.host());
host = constants.host(host);
port = constants.port(port);
username = constants.username(username);
password = constants.password(password);
}
property file...
host=127.0.0.1
port=3306
username=root
password=root
On Wed, Aug 6, 2014 at 7:37 AM, Najeeb Shah <snajeebu...@gmail.com> wrote:
I am new to GWT, I want to read property file on Server side. I have DBConfig.java, useDBConfig.java and DBConfig.properties all placed in server package. I can't read the values from property file on Server Side. Your help is highly appreciated.
There could be a solution of JSON etc. I don't know about that stuff. Could someone please help me out.
Where in the folder hierarchy is the properties file placed?
You have a few options here: you can use App Engine's own service to store system properties or you can use your current design of loading a file. If you want to use App Engine's system properties, see this documentation for setting it up: https://developers.google.com/appengine/docs/java/configyaml/appconfig_yaml#Java_app_yaml_System_properties_environment_variables_and_context_parameters
If you still want to read from a properties file, you can use the below sample code which will load in a properties file and store the info inside a Properties object (you need to run this code within a servlet since it needs access to a ServletContext):
InputStream properties_stream = this.getServletContext().getResourceAsStream("/WEB-INF/prop.properties");
Properties app_properties = new Properties();
app_properties.load(properties_stream);