SimpleAddressBook and Jetty Standalone

Hi

I hope this hasn’t been discussed already as I used the search and all that helped did unfortunately not solve my problem.

My premise: I want to run a Vaadin app through a standalone managed Jetty. I tested the Jetty in Eclipse, everything seems to work fine. Now, I referred to this
http://vaadin.com/forum/-/message_boards/message/17934
and this
http://vaadin.com/forum/-/message_boards/message/71753
and everything looks identical with me. But still I run into the problem, that as soon as I want to access SimpleAddressBook I get the following error:

Problem accessing /SimpleAddressBook. Reason:

SimpleAddressBook cannot be cast to com.vaadin.Application

Caused by:

java.lang.ClassCastException: SimpleAddressBook cannot be cast to com.vaadin.Application
at com.vaadin.terminal.gwt.server.ApplicationServlet.getNewApplication(ApplicationServlet.java:82)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.createApplication(AbstractApplicationServlet.java:802)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.findApplicationInstance(AbstractApplicationServlet.java:630)
at com.vaadin.terminal.gwt.server.AbstractApplicationServlet.service(AbstractApplicationServlet.java:400)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:530)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:426)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:118)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:495)
at org.eclipse.jetty.server.session.SessionHandler.handle(SessionHandler.java:179)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:930)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:361)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:864)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:116)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:112)
at org.eclipse.jetty.server.Server.handle(Server.java:337)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:552)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:979)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:533)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:203)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:399)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:437)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:435)
at java.lang.Thread.run(Unknown Source)

The source of SimpleAddressBook is a complete copy of http://vaadin.com/tutorial, the SVN, without any changes made to it. Still I get this error. Everything seems to be fine:


import com.vaadin.Application;

public class SimpleAddressBook extends Application {

I hope anybody can help me with this problem. Thanks already in advance.

Regards

This sounds very much like a classpath issue. If the application and the Vaadin JAR being used by Jetty have been loaded with different (and unrelated) classloaders, they might see two “different” com.vaadin.Application classes.

Do you have e.g. a Vaadin JAR in the WebContent directory and another one explicitly referenced from the classpath used by Jetty?

Hi

I had the same idea but I did not find a consistency problem (or at least I do not anymore where to look). I created the project like suggested through the tutorial (Eclipse → Dynamic Web Project). Vaadin was downloaded and added automatically to the Web App Libraries as I can see it now. Nothing more was added by me to the project as libraries.

So, the main origin point was with the Dynamic Web Project and just the two classes of the SimpleServer and SimpleAddressBook copied. I am actually not sure how Eclipse handles this, but as the Build Path seem to be configured correctly, I hoped this it.

I am open for other suggestions or ways I maybe restart the project creation.

Hi again

OK, I did some tests now. What throws him out of line is the following

webappcontext.setWar(“WebContent”);

as it normally can work (as directory) and should, if probably nothing else requires some dynamic loading I could think.
If I deploy the web application and set the war

webappcontext.setWar(“webcontent.war”);

it works (another thing was that I forgot the vaadin package but that is now all included). Deployed everything works. Dynamic it does not.

If this helps maybe, I really would like to be able to make it through dynamics and not deployed all the time. This should work somehow, maybe just a small Eclipse setting…

Its me again and again ^^’

Another think I now tested and found out:
As mentioned I created a Dynamic Web Project through my eclipse3.5. Vaadin downloaded two GWT and a Vaadin lib. The GWT libs were included as external jars whereas the Vaadin lib was added to the WEB-INF/lin directory and included from there as Eclipse Web App Lib.
When I started the Jetty with WebContent (as classically created) as war it gave me that error. Deployed as .war file, no error.

Now, I added all libs, also vaadin lib, as external jars and/or user libraries in eclipse. Start the server, folder WebContent set, voilà it works. This may not be the solution to use or better said, the one aspired, but it is easy, no big change and does work for now. But nevertheless it would be interesting to rifle through the process to see were something goes wrong.

Regards

Classloader issues stated here are most likely because classloader is not set properly. Below code fixes this.

Here’s latest launcher file that should work out of the box with any Eclipse Galileo distributions (Java, Classic or JEE). No other plug-ins are required. It works with any IDE if you add Jetty JAR to your classpath. Hot code replace is almost immediate and works 100% reliably.

Important: remove all other Servlet Containers from your classpath, e.g. Apache Tomcat v6.0.


package com.example.launch;

import org.mortbay.jetty.Server;
import org.mortbay.jetty.webapp.WebAppContext;

public class Launcher {

	private static String contextPath = "/";
	private static String resourceBase = "WebContent";
	private static int httpPort = 8888;

	public static void main(String[] args) throws Exception {
		Server server = new Server(httpPort);
		WebAppContext webapp = new WebAppContext();
		webapp.setContextPath(contextPath);
		webapp.setResourceBase(resourceBase);
		webapp.setClassLoader(Thread.currentThread().getContextClassLoader());
		server.setHandler(webapp);
		server.start();
		server.join();
		System.out.println("Started Jetty " + Server.getVersion()
				+ ", go to http://localhost:" + httpPort + contextPath);
	}

}

Hi, Jani. I’m a newbie in Vaadin. I can’t starting me application ( without HelloWord )) ).

I have a questions - all programs must extends com.vaadin.Aplication ?

I extends of com.vaadin.ui.Link - and got error:

java.lang.ClassCastException: com.example.myproject.MyprojectApplication cannot be cast to com.vaadin.Application

I’m add your class - Launcher to my package nearly my class - MyprojectApplication and delete Apache Tomcat v6.0 from classpath, but error still (((.

My
classpath
and
project structure

Please, help me.

Dani, yes, your application entry point must extend Application class. You can check the micro “HelloWorld” example source
http://demo.vaadin.com/docs/example-source/com/vaadin/demo/HelloWorld.java.html