Eclipse Yoxos Services Downloads Blogs About
Home > Blogs >

Posts Tagged ‘embedded’

on Oct 2nd, 2009Executable WARs with Jetty

Today I want to talk about one of the younger members in the Eclipse family: Jetty. It is great to have such an interesting project on board and it is yet another example of how Eclipse has become more than just an IDE.

What I wanted to with jetty was to create an executable, standalone and self-contained WAR. I first encountered this concept in Hudson. The hudson.war contains an embedded Winstone servlet container, which makes it possible to run the application by executing

java -jar hudson.war

This makes test driving the application really simple. The idea was to do the same with Jetty. Embedding the Jetty runtime in the war proved to be the easy part, as it was just a matter of declaring the jetty dependencies in the maven pom.xml.

The tricky part was telling jetty where to find the war-file to serve. My first try was to hardcode the filename, but that left a foul aftertaste. Finding a solution took quite some time, which is why I am posting this for future reference. This is the Main-Class used to bootstrap Jetty (adapted from the Wicket quickstart archetype):

import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.bio.SocketConnector;
import org.mortbay.jetty.webapp.WebAppContext;
 
public class Start {
 
  public static void main(String[] args) throws Exception {
    Server server = new Server();
    SocketConnector connector = new SocketConnector();
 
    // Set some timeout options to make debugging easier.
    connector.setMaxIdleTime(1000 * 60 * 60);
    connector.setSoLingerTime(-1);
    connector.setPort(8080);
    server.setConnectors(new Connector[] { connector });
 
    WebAppContext context = new WebAppContext();
    context.setServer(server);
    context.setContextPath("/");
 
    ProtectionDomain protectionDomain = Start.class.getProtectionDomain();
    URL location = protectionDomain.getCodeSource().getLocation();
    context.setWar(location.toExternalForm());
 
    server.addHandler(context);
    try {
      server.start();
      System.in.read();
      server.stop();
      server.join();
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(100);
    }
  }
}

The interesting bit is the getProtectionDomain()/getCodeSource() part, which tells us the location of the war-file. That’s all there is to it. Presto, executable web-application powered by Jetty in jar.

Edit: Added the import statements as per Tim’s suggestion.

on Jun 22nd, 2009Eclipse Embedded Day 2009

Eclipse Embedded Day happens this week on June 25th, 2009, just a day after the Eclipse Galileo release.

edaybanner Eclipse Embedded Day 2009

What is Eclipse Embedded Day? Well, it’s a day long event for people in the automotive, telematics, mobile, consumer electronic and medical industry to learn how to better leverage Eclipse technology and the Eclipse community as part of their development strategy. The event will focus on three themes:

  • Eclipse as a platform for application development in the embedded space;
  • Collaborating with the open source community, Working Groups;
  • Case studies of projects of companies in the automotive, telematics, medical or consumer electronics area

The agenda is packed!

agenda 300x178 Eclipse Embedded Day 2009

EclipseSource is co-sponsoring the event and in particular, our Jochen Krause will be giving the opening keynote on provisioning and managing embedded systems using Eclipse technology.

If you’re interested in the embedded space, I highly recommend attending this event.

© EclipseSource 2008 - 2011