views:

201

answers:

2

I would like to start with Java web development. First I would like to setup a good development environment using an Jetty server in Eclipse, which would allow for short development cycles. But I am struggling to set it up.

There are other questions about it, but they are either old or incomplete for me. I have seen suggestions for using a plugin, but the plugins seem to be out of date. Also I don't wont to be requierd to use Maven at the beginning.

I have seen ways to set up Jetty in Eclipse without an plugin:

But for me as a novice on server-side Java and Jetty, they are incomplete.

I followed the steps in the linked article. But on step 2 I don't know what content web.xml should have, I created an empty XML file. And when I try to run the server on step 4 I get java.lang.ClassNotFoundException: org.mortbay.jetty.webapp.WebAppContext

How do I setup Jetty with Eclipse without plugin?

UPDATE

As waxwing suggested, I should change the class since it has changed from Jetty 6 to Jetty 7. I started the Jetty server again and now I get NoSuchMethodException:

2010-07-25 13:37:22.849:WARN::Config error at <Set name="var">../sampleweb/sampleweb_webroot</Set> java.lang.NoSuchMethodException: class org.eclipse.jetty.webapp.WebAppContext.setVar(class java.lang.String)
2010-07-25 13:37:22.849:WARN::Unable to reach node goal: started
java.lang.NoSuchMethodException: class org.eclipse.jetty.webapp.WebAppContext.setVar(class java.lang.String)

My sampleweb.xml that is placed in the context directory in my Jetty project and has this content, taken from the article:

<?xml version="1.0" encoding="UTF-8"?>
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/app</Set>
<Set name="var">../sampleweb/sampleweb_webroot</Set>
<Set name="extractWAR">true</Set>
<Set name="copyWebDir">false</Set>
<Set name="defaultDescriptor">
<SystemProperty name="jetty.home" default="."/>
/etc/webdefault.xml</Set>
</Configure>

I would likte to set up a simple Hello World servlet.

A: 

You need the jetty server adapter - look for install new server - which allow you to work with an unzipped jetty 6.

Thorbjørn Ravn Andersen
A: 

The guide is incomplete in that the technology stack has not been chosen for you. An empty web.xml should run fine - but it also nothing would be published by Jetty. In other words, there is access point into your application.

There should be many references to a web.xml. See this example. The <servlet-class> subelement of <servlet> points out a class that implements javax.servlet.Servlet, which is a rudimentary interface for classes handling web requests.

On the other hand, you can use something like the Spring framework, then you use another approach, where you register Spring itself as a servlet (or a servlet listener). See this example from the official documentation. There are lots of other web frameworks out there that all require different layouts of web.xml.

As for your second problem, are you using Jetty 6? The guide is written for Jetty 6 and will not work for newer versions since class names have changed. And if you are using Jetty 6, consider installing the Jetty server adapter that Thorbjørn Ravn Andersen suggests in his answer.

waxwing
Thanks, I am using Jetty 7, and has changed the class name now. I don't understand how I should configure my `web.xml` for a simple "Hello World" servlet. Now I got an `NoSuchMethodException` instead, see my updated question.
Jonas