File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Products » Other Open Source Projects
Bookmark "Velocity Error:Resource Not Found Exception" Watch "Velocity Error:Resource Not Found Exception" New topic

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(
at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(
at org.apache.velocity.runtime.RuntimeSingleton.getTemplate(
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.


Carol Enderlin
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
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

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

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

[java] Hello World!

Total time: 8 seconds
I agree. Here's the link:
subject: Velocity Error:Resource Not Found Exception
It's not a secret anymore!