Help loading XML config file via Init Servlet
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Hello,
I am using the Apache Commons Digester to load an XML config file via a servlet with init params...
I keep getting this error when I start Tomcat 5.5.9 and have deployed the war file via my build script:
As one can see there's an obvious pathing issue:
As one can see there's an obvious pathing issue.
Where does the tomcat_home/bin/... come from? The "bin" directory is not supposed to be there!
Here's the specific target from my build script which places attributes-config.xml into tomcat_home/WEB-INF/classes/org/coffeebreak/config:
Here's my deployment descriptor (web.xml) file:
Here's my init servlet for the XML file:
My helper file (which is showing that the rules file is not loading):
What could I possibly be doing wrong?
Why is it stating this when I start Tomcat:
it should be without the "bin" directory, like this:
Why is the rules file coming out as null?
Sincerely,
James Dekker
[ January 14, 2007: Message edited by: James Dekker ]
I am using the Apache Commons Digester to load an XML config file via a servlet with init params...
I keep getting this error when I start Tomcat 5.5.9 and have deployed the war file via my build script:
As one can see there's an obvious pathing issue:
As one can see there's an obvious pathing issue.
Where does the tomcat_home/bin/... come from? The "bin" directory is not supposed to be there!
Here's the specific target from my build script which places attributes-config.xml into tomcat_home/WEB-INF/classes/org/coffeebreak/config:
Here's my deployment descriptor (web.xml) file:
Here's my init servlet for the XML file:
My helper file (which is showing that the rules file is not loading):
What could I possibly be doing wrong?
Why is it stating this when I start Tomcat:
it should be without the "bin" directory, like this:
Why is the rules file coming out as null?
Sincerely,
James Dekker
[ January 14, 2007: Message edited by: James Dekker ]
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
In web applications, never use relative paths to files, always absolute paths. What the relative path might be is unspecifed, ans sometimes unpredictable, and it varies from one container to the next.
You can convert a relative path to an absolute one like this:
absolutePath = conf.getServletContext().getRealPath("/") + relativePath
[ January 14, 2007: Message edited by: Ulf Dittmer ]
You can convert a relative path to an absolute one like this:
absolutePath = conf.getServletContext().getRealPath("/") + relativePath
[ January 14, 2007: Message edited by: Ulf Dittmer ]
James Dekker
Ranch Hand
Posts: 231
1
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Mr. Dittmer,
The problem with getRealPath() is that if you set unpackWars="false" then the file returns as null. getRealPath() is raw File I/O.
What am I doing wrong with my code? Why isn't it finding the xml config file?
Sincerely,
JD
The problem with getRealPath() is that if you set unpackWars="false" then the file returns as null. getRealPath() is raw File I/O.
What am I doing wrong with my code? Why isn't it finding the xml config file?
Sincerely,
JD
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
If you are not unpacking the wars, then you cannot expect the files to live anywhere on the file-system. If you need the files in the file system, don't use unpacked wars.
If you want to read a resource without unpacking, you may wish to explore the getResourceAsStream() method of ServletContext.
If you want to read a resource without unpacking, you may wish to explore the getResourceAsStream() method of ServletContext.
James Dekker
Ranch Hand
Posts: 231
1
posted 18 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Bear,
When I tried your suggestion (using getServletContext()), I got a different error...
Here's my change:
Here's the error message:
When I tried to use the getResourceAsStream() method, by doing this:
I got this error message in Eclipse:
Thank you for your insight!
Sincerely,
James
[ January 14, 2007: Message edited by: James Dekker ]
When I tried your suggestion (using getServletContext()), I got a different error...
Here's my change:
Here's the error message:
When I tried to use the getResourceAsStream() method, by doing this:
I got this error message in Eclipse:
Thank you for your insight!
Sincerely,
James
[ January 14, 2007: Message edited by: James Dekker ]
| Water! People swim in water! Even tiny ads swim in water: Paul Wheaton's 16th Kickstarter: Gardening playing cards for gardeners and homesteaders https://coderanch.com/t/889615/Paul-Wheaton-Kickstarter-Gardening-playing |













