1
votes

I have huge problems trying to get the simplest Velocity project to run in Eclipse 4.4 (Luna).

I created a dynamic web project running on a Tomcat 7.0 server which has been setup and started from within Eclipse.

I add a simple index.vm to the WebContent folder:

<html>
<body>
#set( $foo = "Velocity" )
Hello $foo World!
</body>
<html>

I modify the web.xml like so:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID"
  version="2.5">

<display-name>Velocity_Test</display-name>
<welcome-file-list>
<welcome-file>index.vm</welcome-file>
</welcome-file-list>

<servlet>
<servlet-name>velocity</servlet-name>
<servlet-class>
  org.apache.velocity.tools.view.servlet.VelocityViewServlet
</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>velocity</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping>
</web-app>

No init-params are used.

The problem seems to be with the jars.

I have tried to copy the two Velocity 1.7 jars into the WEB-INF/lib folder.

I have tried to add the jars as external jars in the java build path properties.

I have tried to add the references to the jars in the deployment assembly.

Yet, no matter what I try the result is always:

HTTP Status 500 - Error instantiating servlet class org.apache.velocity.tools.view.servlet.VelocityViewServlet

exception:

javax.servlet.ServletException: Error instantiating servlet class org.apache.velocity.tools.view.servlet.VelocityViewServlet org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)

root cause:

java.lang.ClassNotFoundException: org.apache.velocity.tools.view.servlet.VelocityViewServlet org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603) org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310) java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) java.lang.Thread.run(Unknown Source)

Any help would be welcome.

Cheers, Dennis

1
Post the complete error log. And think about use a tool like maven to build and manage yours project dependencies.José Ricardo Pla
I added the exception and root cause to the description.Dennis Bauszus

1 Answers

1
votes

The reason is the ClassNotFoundException. Add the dependencies to the project. If you use maven (or another tool to build your projects) is as simple as adding the dependency to the pom.xml file.

<dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>1.7</version>
</dependency>