• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Velocity Error:Resource Not Found Exception

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
reply
    Bookmark Topic Watch Topic
  • New Topic