You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Dave Dutcher <dj...@earthlink.net> on 2002/07/21 19:41:57 UTC

Resource Not Found Exception

Hello,

I'm working on a web application using servlets and Velocity, and I'm
getting a Resource Not Found Exception.  I had it working on my Win XP
desktop machine, and now I'm uploading it to an ISP.  The ISP runs solaris,
and they told me the path to the directory with my htm files is
"/usr/local/etc/httpd/sites/bigleaguepools.com/htdocs/"

To test that the directory is right I wrote this code in my servlets:

String path = "/usr/local/etc/httpd/sites/bigleaguepools.com/htdocs/";
String template = "Admin Step 1.htm";

File file = new File( path, template );
response.setContentType("text/html");
PrintWriter out = response.getWriter();

if ( file.canRead() )
{
	out.println("canRead() succeeded.");
	BufferedReader br = new BufferedReader( new InputStreamReader( new
BufferedInputStream(new FileInputStream(file.getAbsolutePath()))) );
	int i;
	for (i=0;i<10;i++)
	{
		out.println(br.readLine());
	}
}

And sure enough that worked.  It outputed the first 10 lines of the file I
wanted.  Then I tried configuring Velocity like this:

String path = "/usr/local/etc/httpd/sites/bigleaguepools.com/htdocs/";
Properties props = new Properties();
props.setProperty(Velocity.FILE_RESOURCE_LOADER_PATH, path);
Velocity.init(props);

Then I try creating a Template like this:

String file = "Admin Step 1.htm";
Template template = org.apache.velocity.runtime.Runtime.getTemplate(file);

But that throws this exception:

org.apache.velocity.exception.ResourceNotFoundException: Unable to find
resource 'Admin Step 1.htm'
	at
org.apache.velocity.runtime.resource.ResourceManager.getResource(ResourceMan
ager.java:438)
	at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java
:736)
	at
org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java
:718)
	at
org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.ja
va:337)
	at org.apache.velocity.runtime.Runtime.getTemplate(Runtime.java:319)
	at SportsPool.OutputVelocityTemplate(Unknown Source)

Does anyone have any ideas why I'm getting the exception?

Thanks for the help,

Dave


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Resource Not Found Exception

Posted by Dave Dutcher <dj...@earthlink.net>.
Well, I seem to have found the answer to my own problem.  I guess I should
have known that the first thing to do when there is a problem is to check
the log file.  The only problem was that there was no Velocity.log file
being created on the Solaris machine even though there was one on my XP
machine.  I figured it was trying to create the log file in an unusable
directory, so I set the property that specifies the log files name, and then
suddenly everything is working.

I'm a little surprised by this because if the problem was that it was unable
to write to the log, I would have expected a different error message.  Also
calling Velocity.init() did not throw any exceptions and I believe it tries
to write to the log when init is called.  Oh well, its working, I'm happy
now.  :)

Thanks,

Dave


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>