Jetty Standalone Setup Help

I am considering using itmill for our project. I want to create a setup for jetty standalone (not the standard java web setup) with itmill. Anybody could help?

What I really meant was Jetty run inside an application in embedded mode. Any help?

IT Mill Toolkit distribution comes with integrated Jetty, so I would say somebody definitely can help you. :slight_smile:

First take a look at:

Also, some time ago I made experiments with “desktop web application” packaging as a stand-alone application ( executable jar and windows exe). Back then I was
using the Winstone servlet container
.

Servlet packaging and classloading are the biggest challenges, but IT Mill Toolkit should work as in any web application.

  1. add this class to your project, e.g. as StartServletContainer.java


import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.nio.SelectChannelConnector;
import org.mortbay.jetty.webapp.WebAppContext;

/**
 * Start IT Mill Toolkit example application as standard java program. Uses
 * Jetty Servlet Container which is easy to run / debug with e.g. Eclipse IDE.
 *  
 */
public class StartServletContainer {

	public static int PORT = 8888;

	public static void main(String[] args) {

		try {
			final Server server = new Server();

			final Connector connector = new SelectChannelConnector();
			connector.setPort(PORT);
			server.setConnectors(new Connector[] { connector });

			final WebAppContext webappcontext = new WebAppContext();
			webappcontext.setContextPath("");
			webappcontext.setWar("WebContent");

			server.setHandler(webappcontext);
			server.start();
			System.out.println("Jetty started, please go to http://localhost:"
					+ PORT + "/");
		} catch (final Exception e) {
			e.printStackTrace();
		}

	}

}
  1. add these three classes to your classpath

jetty-6.1.7.jar
jetty-util-6.1.7.jar
servlet-api-2.5-6.1.7.jar
  1. Add file WebContent/WEB-INF/web.xml

<?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>IT Mill Toolkit example application</display-name>

	<servlet>
		<servlet-name>exampleApplication</servlet-name>
		<servlet-class>
			com.itmill.toolkit.terminal.gwt.server.ApplicationServlet
		</servlet-class>
		<init-param>
			<param-name>application</param-name>
			<param-value>
				com.example.ExampleApplication
			</param-value>
		</init-param>
	</servlet>

	<!-- Toolkit example application -->
	<servlet-mapping>
		<servlet-name>exampleApplication</servlet-name>
		<url-pattern>/exampleApplication/*</url-pattern>
	</servlet-mapping>

	<!-- Let any Toolkit servlet to handle static files too (/ITMILL/* resources) -->
	<!-- In production environment we can let e.g. Apache handle these more efficiently -->
	<servlet-mapping>
		<servlet-name>exampleApplication</servlet-name>
		<url-pattern>/ITMILL/*</url-pattern>
	</servlet-mapping>

	<!-- redirects us to example application -->
	<welcome-file-list>
		<welcome-file>index.html</welcome-file>
	</welcome-file-list>

</web-app>
  1. Then execute StartServletContainer.java as standard java executable, e.g. from Eclipse “Run as Java application” or “Debug as Java application”

  2. Surf to http://localhost:8888

Thousands Thanks. I will try that pronto. Thank you.

Here’s latest launcher file that should work out of the box with any Eclipse Galileo distributions (Java, Classic or JEE). No additional plug-ins, JARs or Servlet Container downloads and installations are required. Eclipse already contains Jetty. Hot code replace is almost immediate and works 100% reliably.

For other IDE’s except Eclipse, add download and add Jetty JARs to your classpath.

Important: remove all other conflicting 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 there,

i have tried to use Jani Laakso Launcher-Class to start a VaadinApplication with Eclipse and Jetty. The start works, i can go to the main site and i can see my label. But when I change the labeltext in eclipse, and start the application with “?restartApplication” there is no change to see :frowning:

Can anyone help me?

web.xml


<?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>JettyTest</display-name>
  <context-param>
  	<description>
  	Vaadin production mode</description>
  	<param-name>productionMode</param-name>
  	<param-value>false</param-value>
  </context-param>
  <servlet>
  	<servlet-name>Jettytest Application</servlet-name>
  	<servlet-class>
  	com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
  	<init-param>
  		<description>
  		Vaadin application class to start</description>
  		<param-name>application</param-name>
  		<param-value>com.example.jettytest.JettytestApplication</param-value>
  	</init-param>
  </servlet>
  <servlet-mapping>
  	<servlet-name>Jettytest 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>

The Application


package com.example.jettytest;

import com.vaadin.Application;
import com.vaadin.ui.Label;
import com.vaadin.ui.Window;

public class JettytestApplication extends Application {
	@Override
	public void init() {
		Window mainWindow = new Window("Jettytest Application");
		Label label = new Label("Hello Vaadin user12312312312");
		mainWindow.addComponent(label);
		setMainWindow(mainWindow);
	}

}

When I start the Launcher-Class i see following message:

And here you can find my sturcture of the eclipse-project:

Any idea?

Thanks!

Quick shot in the dark from the been-there-done-that department: did you by any chance start the server with “run” instead of “debug”?

Best Regards,
Marc

Oh, that’s awkward :frowning: I’m sorry, Marc was right, i started it in normal mode instead of the debug mode… Thank’s a lot!