For some reason, I thought velocity just automatically picked up the velocity.properties file from the classpath, but apparently not. When I changed my init code from "Velocity.init()" to
VelocityEngine ve = new VelocityEngine(); final InputStream resourceStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("velocity.properties"); final Properties velocityProps = new Properties(); velocityProps.load(resourceStream); ve.init( velocityProps ); then everything worked, - Dave Nathan Bubna wrote: > > Where are you iniitializing Velocity? If you're not, then you are > relying on the auto-init, which doesn't (IIRC) search for your > velocity.properties file. You'll need to tell Velocity where to find > the configuration, otherwise it is using the default > FileResourceLoader and is looking in the root directory (as far as > your JVM knows) for the template. > > On Mon, Jul 11, 2011 at 7:12 AM, laredotornado <laredotorn...@gmail.com> > wrote: >> >> Hi, >> >> I'm trying to test something using Velocity 1.6.2 in JUnit 4, but I'm >> having >> trouble getting Velocity to find my email template. I have verified in >> the >> JUnit test that both my velocity.properties and emailTemplate.vm file can >> be >> found on the classpath, yet I get a "ResourceNotFoundException" on the >> 'Velocity.getTemplate("email_template.vm");' line of the code below ... >> >> @Test >> public void testJob() throws Exception { >> try { >> InputStream stream = >> Thread.currentThread().getContextClassLoader().getResourceAsStream("email_template.vm"); >> log.info("stream:" + stream); >> >> InputStream stream2 = >> Thread.currentThread().getContextClassLoader().getResourceAsStream("velocity.properties"); >> log.info("stream2:" + stream2); >> >> Velocity.init(); >> >> final Template template = >> Velocity.getTemplate("email_template.vm"); >> >> Here is my velocity.properties file >> >> =============Begin velocity.properties ========================= >> # >> # velocity.properties - example configuration >> # >> >> >> # uncomment the next two lines to load templates from the >> # classpath (WEB-INF/classes) >> resource.loader=class >> class.resource.loader.class=org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader >> ==============End velocity.properties ========================= >> >> >> >> Any ideas? I'm using Maven 3.0.3 and placing the velocity.properties >> file >> in my src/test/resources directory. The email template file lives in the >> same place. Thanks for any advice, - Dave >> -- >> View this message in context: >> http://old.nabble.com/Classpath-troubles-%28ResourceNotFoundException%29-tp32037826p32037826.html >> Sent from the Velocity - User mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org >> For additional commands, e-mail: user-h...@velocity.apache.org >> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org > For additional commands, e-mail: user-h...@velocity.apache.org > > > -- View this message in context: http://old.nabble.com/Classpath-troubles-%28ResourceNotFoundException%29-tp32037826p32039145.html Sent from the Velocity - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscr...@velocity.apache.org For additional commands, e-mail: user-h...@velocity.apache.org