0

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/

  • -WEB-INF
  • -Props.properties
  • -Props2.properties
NOOB_USER
  • 123
  • 1
  • 2
  • 9
  • where exactly is the properties file located? Right under the war directory or inside WEB-INF? Post the full path and also post the structure of your WAR – Pat Jul 25 '14 at 05:30
  • @Pat I've updated the details. – NOOB_USER Jul 25 '14 at 05:36

1 Answers1

1

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

Community
  • 1
  • 1
Pat
  • 2,026
  • 4
  • 17
  • 21
  • I tried putting the properties file in the WEB-INF folder and it doesn't work. – NOOB_USER Jul 25 '14 at 07:54
  • I used System.getProperty("user.dir"); and placed my config files in glassfish3\glassfish\domains\domain1\config and it worked, thanks btw. – NOOB_USER Jul 31 '14 at 00:45