I know there are lots of similar questions out there, but none of which that helped. We have a GWT application running on a tomcat server, which is loading a properties file for
If you properties file is in the same directory as the class you use to call "getResourceAsStream(..)", then you just need the name of the file, without the absolute path to it. For example, supposing you have:
// notice that your build should copy this from the source directory to your /WEB-INF/classes/.... directory automatically so you can do a clean build
com/x/monitorui/server/configuration.properties
and a class located at the same directory, ie. in package:
com.x.monitorui.server.DatabaseConnection
then you can simply call
Properties properties = new Properties();
properties.load(DatabaseConnection.class.getResourceAsStream("configuration.properties"));
Wo do nearly the same here with "Packager.class" as a class in the same directory; The idea here is to find the path via the class path, which works on tomcat:
final ClassPool pool = ClassPool.getDefault( );
final Class<?> baseClass = Packager.class;
pool.insertClassPath( new ClassClassPath( baseClass ) );
final URL url = pool.find( baseClass.getName( ) );
String pathToBaseClass = url.toURI( ).getPath( );
String baseDir = pathToBaseClass.substring( 0, pathToBaseClass.indexOf( "com" ) - 1 );