NOOB_USER
NOOB_USER

Reputation: 163

GWT Project reads properties file correctly at dev mode, but couldn't find it when I deployed it

So I have 2 jar files referenced to my GWT Project, both reads properties file this way:

String PROPS_FILE = "Props.properties"
Properties propFile = new Properties();
propFile.load(new FileInputStream(PROPS_FILE));

BOTH jar files are coded in java and exported as JAR libraries.

The properties file are located at the war folder in dev mode.

It works properly at dev mode but when I try it when It's deployed it encounters the error

java.io.FileNotFoundException: Props.properties (No such file or directory).

Is there anyway to make this work without modifying the JARs? Thanks.

The folder structure is like this:

WAR
-WEB-INF
-Props.properties
-Props2.properties

After compiling the project to .war file and deploying using glassfish, the folder structure is like this:

(PATH ETC...)/applications/SAMPLEGWTAPP/

Upvotes: 0

Views: 371

Answers (1)

Pat
Pat

Reputation: 2257

Option 1: When you run GWT in prod mode, WEB-INF/classes of the WAR is there on its classpath by default. Try putting your properties file right under the WEB-INF/classes. If your server still can't find the properties file, then use below code:

InputStream is = this.getClass().getClassLoader().getResourceAsStream("Props.properties");
Properties myProps = new Properties();
myprops.load(is);

Option 2: Externalize the location and put it outside your project strcture - e.g. under a properties directory somewhere on the filesystem. Then, you can add this properties directory to your classpath in your IDE (in Eclipse, you can do this by Build Path > Add Variable) and also add it in the classpath while running it in the server - refer to your server's documentation about how to add a classpath. E.g. to add a directory to classpath in tomcat, you have to do it like mentioned here Adding a directory to tomcat classpath

Upvotes: 1

Related Questions