David Smith wrote: > John Willemin wrote: > >> Tomcat 6.0.16 >> Linux 2.6.18 >> JDK 1.6.0_05 >> >> Imagine a webapp like this: >> /index.jsp >> /WEB-INF >> -web.xml (of course) >> -/classes >> --ConfigFile.txt >> -/lib >> --MyConfigLoader.class >> >> If I want to load ConfigFile.txt into an InputStream from inside my >> webapp, all I have to do is this: >> >> InputStream configStream = >> this.getClass().getClassLoader().getResource("/ConfigFile.txt"); >> >> In some cases, I may want to run multiple instances of the application but >> have them share one copy of the configuration file. The idea is that I >> only want to have to maintain one version of the config file per Tomcat >> and have all the webapps use the same copy. If I put ConfigFile.txt inside >> /tmp, for instance, this works fine: >> >> InputStream configStream = new FileInputStream("/tmp/ConfigFile.txt"); >> >> But what I tried doing was, symbolically linking all the different webapps >> to one copy of the file. In other words, >> tomcat/webapps/myapp1/WEB-INF/classes/ConfigFile.txt and >> tomcat/webapps/myapp2/WEB-INF/classes/ConfigFile.txt would just be >> symlinks to /tmp/ConfigFile.txt. >> >> When I do this, the input stream comes up null: >> InputStream configStream = >> this.getClass().getClassLoader().getResource("/ConfigFile.txt"); >> >> I thought that symlinks were just treated like files, and that this should >> just work. I stepped through org.apache.catalina.loader.WebappClassLoader >> in the Eclipse debugger and I can't see anything that would obviously >> prevent symlinks from working. But the only time that the ConfigFile.txt >> shows up in the resourceEntries Map as a ResourceEntry is when I have the >> file physically inside WEB-INF/classes - never when it is only a symlink. >> >> I have googled many combinations of >> java/linux/classloader/tomcat/symlink/symbolic link/classpath and not >> found anything quite like this yet. >> >> Any ideas? >> >> Thanks! >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org >> For additional commands, e-mail: users-h...@tomcat.apache.org >> >> >> > If you look at all the third party repackages of tomcat that fail, > you'll see a theme -- symlinks cause problems in java. I would highly > recommend you find a way to maintain that config file via the build > system and have a copy in each of the webapps. Either that or put a > copy in tomcat's lib folder where it becomes accessible to all webapps > in the environment. > > --David > > >
Ooops ... I mean tomcat's common classes folder. See the classloader docs for your version of tomcat for details of where that is and/or what needs to be configured to enable it. --David --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org