views:

50

answers:

1

Hi,

I am getting the following error when I try to access access Velocity template using URLResourceLoader.

org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'http://localhost:8080/myvelocityapp/my-template.vm' at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:483)

I am able to see the above file if i copy paste the URL into my browser. However the code is not able to access the URL. My templating code seems to be correct because it works fine when i try to use ClassPathResourceLoader. It is just the url resource loader which gives problem.

Thanks.

EDIT---

I wrote a small jUnit to see what the problem is:

import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import junit.framework.TestCase;

public class TestUrl extends TestCase {

    protected void setUp() throws Exception {
        super.setUp();
    }

    public void testVelocity() throws IOException {
        URL url= new URL("http://localhost:8080/myvelocityapp/my-template.vm");
        System.out.println(url.openStream().toString());

    }

    protected void tearDown() throws Exception {
        super.tearDown();
    }

}

And the above code is able to access the URL.

A: 

Finally found the issue.

The problem was that "url.resource.loader.root" was not specified.

Apache Fan