Posts

Showing posts with the label Classpath

ClassLoader GetResourceAsStream Returns Null

Answer : If it's in the same package use InputStream is = Driver.class.getResourceAsStream("myconfig.txt"); The way you have it InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("myconfig.txt"); It's looking for the file in the root of the classpath. You could use InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("com/me/myapp/myconfig.txt"); The rules for searching are explained in the javadoc of ClassLoader#getResource(String) and the javadoc of Class#getResource(String) . If you are working with Maven, add the following lines under BUILD tag. You get this error when you are running the webapp on server but there is no reference to the resources on the server. So, add this the following into your POM.xml and see the magic. <resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <...

Adding An External Directory To Tomcat Classpath

Answer : Just specify it in shared.loader or common.loader property of /conf/catalina.properties . See also question: Can I create a custom classpath on a per application basis in Tomcat Tomcat 7 Context hold Loader element. According to docs deployment descriptor (what in <Context> tag) can be placed in: $CATALINA_BASE/conf/server.xml - bad - require server restarts in order to reread config $CATALINA_BASE/conf/context.xml - bad - shared across all applications $CATALINA_BASE/work/$APP.war:/META-INF/context.xml - bad - require repackaging in order to change config $CATALINA_BASE/work/[enginename]/[hostname]/$APP/META-INF/context.xml - nice , but see last option!! $CATALINA_BASE/webapps/$APP/META-INF/context.xml - nice , but see last option!! $CATALINA_BASE/conf/[enginename]/[hostname]/$APP.xml - best - completely out of application and automatically scanned for changes!!! Here my config which demonstrate how to use development version of project files ...