The classes directory is for compiled Java classes. Some folks put XML there if it needs to be in the classpath, but I try to avoid this because it "just feels wrong".
Regards,
Eddie
----- Original Message ----- From: "Dinesh Sampangi" <[EMAIL PROTECTED]>
To: "Struts Users Mailing List" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Monday, October 25, 2004 1:40 AM
Subject: Re: Getting a resource from a WAR
Hi! try putting the "myresource.xml" under /WEB-INF/classes/ and get access to it as below.
public void init() throws ServletException { try{ SAXBuilder builder = new SAXBuilder(); URL confFileURL = this.getServletContext().getResource("/WEB-INF/classes/MyResource.xml"); logger.info("the config resource was " + (confFileURL != null ? "found" : "not found")); Document doc = builder.build(confFileURL); logger.info("Root Element -->"+doc.getRootElement()); }catch (MalformedURLException e) { logger.info("Malformed URL Exception"+e.toString()); }catch(JDOMException de){ logger.info("JDOM Exception"+de.toString()); } }
rgds, Dinesh
On Thu, 21 Oct 2004 08:25:31 -0600, kjc <[EMAIL PROTECTED]> wrote:
I have an ActionServlet that subclasses the struts action servlet. In my init() method i'm trying to load a resource like this.
public void init(){
URL url = this.getServletContext().getResource("/myresource.xml");
logger.info("the config resource was " + (url != null ? "found" : "not found"));
}
The "not found" statement is printed.
I checked my .war file and the resource is properly placed under WEB-INF/myresource.xml
Note, that this war file is part of a .ear file.
Thanks in advance.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
-- Dinesh B Sampangi **************************** Software Engineer FCG Software Services, Brigade Road,Bangalore - 560025 Ph: 56917777 ext:2523
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
--- avast! Antivirus: Outbound message clean. Virus Database (VPS): 0443-3, 10/22/2004 Tested on: 10/25/2004 1:52:38 AM avast! - copyright (c) 2000-2004 ALWIL Software. http://www.avast.com
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]