Search code examples
gwtpropertiesserver-side

GWT: Safe place for properties file with db variables


I have a file variables.properties in my GWT application inside the war folder. The file contains a jdbc string, username and password, hence I would not like to see it on the client side in any way.

My question: Is variables.properties somehow integrated into client side code at runtime when placed inside the war folder or is it safe to place it there?

If it is not, where should I put it? I read the file with this code:

variables = new Properties();
BufferedInputStream stream = new BufferedInputStream(new FileInputStream("variables.properties"));
variables.load(stream);
stream.close();

Thanks in advance!


Solution

  • If you don't want the properties to be visible to the GWT client code (or to a web browser poking around) you can load them from your classpath. That way they'll end up in WEB-INF/classes which is not visible. If you're using Maven you can store your properties files in src/main/resources. Otherwise you can store them next to your Java source files and make sure they get copied during your build process. You can load them from the classpath by using: http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getResourceAsStream(java.lang.String)