Files not found in production mode

I have some files which I read from java actions in my project, they are: An xsl file in WEB-INF directory which is used to generate a PDF using Apache FOP. The path to the file is sent to the java action as a parameter from a microflow we send 'WEB-INF\filename.xsl' A properties file in the route of the deployment directory, loaded in Java through creation of a FileInputStream object with the filename as the constructors parameter. When running in test or development both files are read without any problems, however in production mode they both fail. I assume this is becasue the JVMs working directory is set to a different location when in production mode, is this correct and if so is there a way to specfically set it?
1 answers

The layout of the application on the filesystem is often different in various scenarios. To reference a location consistently I usually get the base path at run time (in production this is usually set in application.conf). Ex,

String pathPrefix = com.mendix.core.conf.Configuration.getBasePath().getAbsolutePath();
System.out.println("Path prefix : " + pathPrefix);

Secondly, the path separator for file locations is different between Windows and unix environments ("'\" and "/", resp). When using paths, make sure to use the appropriate slash.

String separator = System.getProperty("file.separator");

Combining these two should give you valid paths in both development and production.

StringBuilder sb = new StringBuilder();

String fullPath = sb.toString();

(Be sure to check the resulting file path on the console, I haven't actually tested this code).