This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Other Open Source Projects and the fly likes Velocity Error:Resource Not Found Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Velocity Error:Resource Not Found Exception" Watch "Velocity Error:Resource Not Found Exception" New topic
Author

Velocity Error:Resource Not Found Exception

Elton Hughes
Ranch Hand

Joined: Jun 19, 2003
Posts: 72
Hello All,

Based on a 9 horse shoe review, I bought Pro Jakarta Velocity. I have just started the book and I am having troubles with the first example program. It is the Velocity version of the famous "Hello World" program. The code is this:


It compiles, but when I run it I get the following message:
-> java org.novaworks.ch02.HelloWorld
Exception in thread "main" org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'src/templates/ch02/HelloWorld.vm'
at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:458)
at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:341)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:831)
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:813)
at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(RuntimeSingleton.java:285)
at org.apache.velocity.app.Velocity.getTemplate(Velocity.java:469)
at org.novaworks.ch02.HelloWorld.main(Unknown Source)
->

It appears that the program is unable to find the template.

Unfortunately, I am at a loss as to how to solve the problem. Any insight and help would be greatly appreciated.

Thanks!

Elton
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
What directory are you running your java command from?

It sounds like it is expecting you to run that from the pro-jakarta-velocity directory. I'm assuming you downloaded the sample code or you put the hello world template where the code is looking for it: "src/templates/ch02/HelloWorld.vm".

It sounds like it needs to be able to find that path from the place you run the java command. If that doesn't work, is the dir containing the src dir on the classpath?

I downloaded the sample chapter and it says about the template, "Save this file to a location where it will be accessible from your code." Not very helpful.
Carol Enderlin
drifter
Ranch Hand

Joined: Oct 10, 2000
Posts: 1364
Actually I didn't feel like messing with setting up the classpath to get the ch 2 hello world to run on the command line so I put this into the build.xml that comes in the sample code



It ran ok for me:

C:\_tools\pro-jakarta-velocity>ant ch2
Buildfile: build.xml

clean:
[delete] Deleting directory C:\_tools\pro-jakarta-velocity\build
[mkdir] Created dir: C:\_tools\pro-jakarta-velocity\build

compile:
[javac] Compiling 88 source files to C:\_tools\pro-jakarta-velocity\build

ch2:
[java] Hello World!

BUILD SUCCESSFUL
Total time: 8 seconds
 
 
subject: Velocity Error:Resource Not Found Exception
 
Similar Threads
Apache Velocity ---ResourceNotFoundException
NoClassDefFoundError: wrong name
Help executing velocity example
What is the role of /Library/Java/Extentions ?
suggestion for html