Can't read property file on Server Side in GWT

277 views
Skip to first unread message

Najeeb Shah

unread,
Aug 6, 2014, 8:37:44 AM8/6/14
to google-a...@googlegroups.com
Hi,

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.

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


I found out that constants couldn't be used on server side. There could be a solution of JSON etc. I don't know about that stuff. Could someone please help me out.

Thanks in advance

Vinny P

unread,
Aug 7, 2014, 11:14:00 PM8/7/14
to google-a...@googlegroups.com

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);

 
 
-----------------
-Vinny P
Technology & Media Consultant
Chicago, IL

App Engine Code Samples: http://www.learntogoogleit.com

Reply all
Reply to author
Forward
0 new messages