From: Keats <ke...@ea...> - 2003-06-24 18:30:45
|
I think I ran into a similar problem trying to run Ignition under ServletExec. I think the spec gives Servlet containers some leeway in how they implement class loaders, and specifically in how they are chained. However, returning a non-null if the resource wasn't found, sounds like it could be a serious Resin bug. If you are trying to load from WEB-INF/classes you obviously need to have a Servlet-aware ClassLoader . The good news is that you don't have to wait for your first request to get the ServletContext -- you can get it during the init() of your Servlet. If you have a WM Broker instance around, you can call getResourceAsStream(), or getResource(), on the Broker. No need to reinvent the wheel. Hope this helps. Keats ----- Original Message ----- From: "Marc Palmer" <ma...@an...> To: <web...@li...> Sent: Tuesday, June 24, 2003 1:37 PM Subject: [Webmacro-devel] Help! (AKA: I hate resin) > > Guys I'd appreciate a hand here - > > Ignition runs fine in Tomcat (for me) but won't start under Resin. > > The problem is that Ignition cannot load resources it requires, namely > properties files, which are in WEB-INF/classes. This may also be the > problem the problem Lane is experiencing with Tomcat on a unix box - though > we can't see why tomcat (or the VM) would vary on this on different > platforms without breaking a lot of stuff. > > Here is an example of my code, which works perfectly under many versions of > Tomcat: > > public PropertiesIgnitionVersionInfo() > { > Properties p = new Properties(); > try > { > p.load( getClass().getResourceAsStream( "/version.properties") ) > ; > } > catch (IOException e) > { > throw new RuntimeException( > "Unable to load version info from classpath: > "+RESOURCE_VERSIONINFO); > } > major = Integer.parseInt( p.getProperty(PROPERTY_MAJORVERSION)); > minor = Integer.parseInt( p.getProperty(PROPERTY_MINORVERSION)); > buildDate = p.getProperty(PROPERTY_BUILD_DATE); > buildName = p.getProperty(PROPERTY_BUILD_NAME); > } > > Now here's the thing. Under resin this fails not because > getResourceAsStream returns null - because it doesn't. > > Resin returns a valid InputStream pointing to ... ? nothing it seems. The > Properties is empty after the call to load. > > Then the parseInt calls die because the property is null. > > Yes I have tried with/without the "/". "/" is the correct thing to do, and > both cases produce the same results in Resin. > > Now I think I have tracked down the problem. Resin is probably using a > classloader that does not defer to the classloader used to load the webapp > resources. > > Stay with me here... in the .WAR the code shown above lives in WEB- > INF/lib/ignition-core.jar but the version.properties file lives in WEB- > INF/classes. > > As a result getClass() is using the classloader used to load the JAR, and > in Resin this means it cannot find anything in WEB-INF/classes - and > erroneously creates an empty input stream instead of null. > > Anyway, the solution to this seems to be to use either the ServletContext > classloader and/or the Servlet classloader to call getResourceAsStream. > > This is not very nice as it means passing ClassLoaders around but is not > the end of the world. > > It just baffles me that Resin is so "bad" like this, but then I suppose I > am doing something a little weird because the files are in different > locations. > > Using ServletContext.getResource is not an option because we're not in a > request yet... and prefixing with WEB-INF/classes would be nasty :) > > Any thoughts gratefully received. > > -- > Marc Palmer > Contract Java Consultant/Developer > > http://www.anyware.co.uk/marc/ > http://www.wangjammers.org > > > > ------------------------------------------------------- > This SF.Net email is sponsored by: INetU > Attention Web Developers & Consultants: Become An INetU Hosting Partner. > Refer Dedicated Servers. We Manage Them. You Get 10% Monthly Commission! > INetU Dedicated Managed Hosting http://www.inetu.net/partner/index.php > _______________________________________________ > Webmacro-devel mailing list > Web...@li... > https://lists.sourceforge.net/lists/listinfo/webmacro-devel |