Vaadin 7 & Embedded Jetty

To all-

I finally have a project that I want to start with Vaadin 7 and so far no success. Unfortunatly, for the past two days I have tried to get Vaadin 7 working with embedded Jetty. One wouldn’t think it would be that hard since I have built several projects with Vaadin 6 and embedded Jetty as a go by.

I don’t know if it is Ivy or if something needs to be configured different in my Jetty setup for Vaadin 7. Any help here would great!

Here is my Jetty Code:


	    Server server = new Server();
	    SocketConnector connector = new SocketConnector();
	    // Set some timeout options to make debugging easier.
	    connector.setMaxIdleTime(1000 * 60 * 10);
	    connector.setSoLingerTime(-1);
	    connector.setPort(port);
	    connector.setReuseAddress(false);
	    QueuedThreadPool pool = new QueuedThreadPool();
	    pool.setMinThreads(10);
	    pool.setMaxThreads(100);
	    pool.setLowThreads(20);
	    pool.setSpawnOrShrinkAt(2);
	    server.setConnectors(new Connector[] { connector });
	    server.setThreadPool(pool);
	    WebAppContext context = new WebAppContext();
	    context.setServer(server);
	    context.setContextPath("/");
	    context.setWar("MyApp.war");
	    server.addHandler(context);
	    try
	    {
	    	server.start();
	    } catch (Exception e) {
	    	   e.printStackTrace()
	    }

and here is my web.xml configuration file:


<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	<display-name>MyApp</display-name>
	<context-param>
		<description>
		Vaadin production mode</description>
		<param-name>productionMode</param-name>
		<param-value>false</param-value>
	</context-param>
	<servlet>
		<servlet-name>MyApp Application</servlet-name>
		<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
		<init-param>
			<description>
			Vaadin UI class to use</description>
			<param-name>UI</param-name>
			<param-value>MyApp.Core.UI.Main</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>MyApp Application</servlet-name>
		<url-pattern>/*</url-pattern>
	</servlet-mapping>
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
		<welcome-file>index.htm</welcome-file>
		<welcome-file>index.jsp</welcome-file>
		<welcome-file>default.html</welcome-file>
		<welcome-file>default.htm</welcome-file>
		<welcome-file>default.jsp</welcome-file>
	</welcome-file-list>
</web-app>

and, finally, the error that I see in my sleep over and over again:


2013-04-23 14:34:41.079::WARN:  failed jsp
java.lang.NoClassDefFoundError: javax/servlet/jsp/JspFactory
	at org.apache.jasper.servlet.JspServlet.init(JspServlet.java:77)
	at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
	at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
	at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:616)
	at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
	at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
	at org.mortbay.jetty.Server.doStart(Server.java:222)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
	at MyApp.Core.Cyclic.WebServer.connectToWebServer(WebServer.java:40)
	at MyApp.Core.Cyclic.Cyclic.main(Cyclic.java:23)
Caused by: java.lang.ClassNotFoundException: javax.servlet.jsp.JspFactory
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 15 more
2013-04-23 14:34:41.079::WARN:  failed org.mortbay.jetty.webapp.WebAppContext@c91629{/,jar:file:/C:/Documents%20and
20Settings/exxxx/workspace7/MyApp/MyApp.war!/}
java.lang.NoClassDefFoundError: javax/servlet/jsp/JspFactory
	at org.apache.jasper.servlet.JspServlet.init(JspServlet.java:77)
	at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
	at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
	at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:616)
	at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
	at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
	at org.mortbay.jetty.Server.doStart(Server.java:222)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
	at MyApp.Core.Cyclic.WebServer.connectToWebServer(WebServer.java:40)
	at MyApp.Core.Cyclic.Cyclic.main(Cyclic.java:23)
Caused by: java.lang.ClassNotFoundException: javax.servlet.jsp.JspFactory
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 15 more
2013-04-23 14:34:41.079::WARN:  Error starting handlers
java.lang.NoClassDefFoundError: javax/servlet/jsp/JspFactory
	at org.apache.jasper.servlet.JspServlet.init(JspServlet.java:77)
	at org.mortbay.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:433)
	at org.mortbay.jetty.servlet.ServletHolder.doStart(ServletHolder.java:256)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
	at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:616)
	at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
	at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1220)
	at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:513)
	at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:448)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
	at org.mortbay.jetty.handler.HandlerWrapper.doStart(HandlerWrapper.java:130)
	at org.mortbay.jetty.Server.doStart(Server.java:222)
	at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:39)
	at MyApp.Core.Cyclic.WebServer.connectToWebServer(WebServer.java:40)
	at MyApp.Core.Cyclic.Cyclic.main(Cyclic.java:23)
Caused by: java.lang.ClassNotFoundException: javax.servlet.jsp.JspFactory
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.net.URLClassLoader$1.run(Unknown Source)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 15 more

Like I said I have been on this googling my brains out but have not come any closer to a good deployment.

You are most likely missing the servlet-api dependency.

Try adding the following dependency (in gradle notation, modify if you’re using something else):

providedCompile group:'javax.servlet', name:'servlet-api', version:'2.5'

John-

Thank you for taking the time to reply to this, but unfortunately, that doesn’t look like it is the issue.

Ivy already has the servlet-api-2.5-6.1.11.jar in the ivy.xml [widgetset-compile]
, plus, I already tried adding it manually with no success.

Any other recommendations to try would be greatly appreciated. The last thing I want to do is start this project in Vaadin 6 and have to convert on a later date.

Regards,
Eric

That should do it, servlet-api should contain the JSPFactory class.

However, the embedded Jetty servers context might be using its own classloader which does not include the projects classpath. You could try setting the context classloader to use the Threads classloader by doing

context.setClassLoader(Thread.currentThread().getContextClassLoader()); and see if it helps.

I am still get the { failed jsp- java.lang.NoClassDefFoundError: javax/servlet/jsp/JspFactory } exception with your proposed change.

Attached are print outs from my build path if that may help.
12930.bmp (1.37 MB)
12931.bmp (1.4 MB)

I have an example with Maven here:
https://code.google.com/a/eclipselabs.org/p/vaadin-push-example/

Just removed the push part, if you don’t need it.

Ray

Raymond-

Your example is definitely provides very good insight on more than one process.

If all else fails, I will try to set up jetty as you have. I am just trying to get it going the way I have been doing it in previous projects. Thanks for the example!

Regards,
Eric

Just a little update on what I have tried.

I have been attempting to use Eclipse Juno with Vaadin 7. All my other projects were in developed in Indigo with Vaadin 6 and they all work as intended. So I decided to just build the exact same simple program that I am attempting in Vaadin 7 and instead, I am trying it with Vaadin 6. In less than 5 minutes, I was able to get the couple of classes together and run the same program without any issues. This leads me to assume that it must be how Ivy is building the dependencies.

I guess I am out of my element when it comes to diving any deeper into this. I am sure that someone has to have build Vaadin 7 using a simple embedded jetty design. It would be very appreciated if someone could post some samples that I could test out or if someone has any suggestions that I could try that would be great.

Best Regards,
Eric

OK, after days of installing, reinstalling, updating, recoding, and pulling my hair out - I finally got it.

I really hope this helps at least one person out there from going through the same headache as I did. I took John Ahlroos’ advice and added the servlet-api-2.5.jar to my build path but that did not help. I actually had to add the jsp-api-2.2.jar into my build path instead and it worked.

I guess you could also use ivy to install the jar by using [below]
in the Ivy.xml configuration file:


<dependency org="javax.servlet.jsp" name="jsp-api" rev="2.2" />
 

So far I have not been a big fan of Ivy.

Best Regards,
Eric

Thanks so much for keeping with this and posting the solution. Solved my problem exactly. And I still have my hair!

Hi all,

Is it possible to avoid the use of web.xml with Vaadin7 + Jetty embedded ? (i am using the API servlet 3.0)

“context.setWar(“MyApp.war”);” => MyApp.war is the Vaadin application ? In this case, we cannot use this code inside Eclipse ?

Eric

It is possible to use Servlet 3.0 annotations to configure Jetty as long as you use new enough a version of Jetty and the classpath is correctly configured. Alternatively, you can configure servlets in your embedded Jetty launcher. If your classpath is ok, you don’t need a WAR file as the context so you can run the application as a normal Java application in Eclipse - see e.g.
our embedded Jetty launcher
which we use in the development of Vaadin framework itself (with some extra features, but using web.xml to configure servlets).

Of course, in Eclipse you can also use the Eclipse plug-in
Run-Jetty-Run
if you don’t really need to embed Jetty in your own application - this is the easy solution for most users.

I assume one of the above is your use case, but in case what you want is to run embedded Jetty as a part of the Eclipse process itself (i.e. as a hidden part of the internals of your custom Eclipse plug-in), it gets more complicated with the classpath and OSGi but is doable…

Thank you again for this tip! It works