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.
我想从Java Web开发开始。首先,我想在Eclipse中使用Jetty服务器设置一个良好的开发环境,这样可以缩短开发周期。但我正在努力设置它。
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.
关于它还有其他问题,但对我来说它们要么旧又不完整。我已经看到了使用插件的建议,但插件似乎已经过时了。我也不会在开始时使用Maven。
I have seen ways to set up Jetty in Eclipse without an plugin:
我已经看到了在没有插件的情况下在Eclipse中设置Jetty的方法:
- Jetty and Eclipse Integration
- Answer to Running Jetty 7 in Eclipse
Jetty和Eclipse集成
回答在Eclipse中运行Jetty 7
But for me as a novice on server-side Java and Jetty, they are incomplete.
但对我来说,作为服务器端Java和Jetty的新手,它们并不完整。
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
我按照链接文章中的步骤进行操作。但是在第2步我不知道web.xml应该有什么内容,我创建了一个空的XML文件。当我尝试在第4步运行服务器时,我得到java.lang.ClassNotFoundException:org.mortbay.jetty.webapp.WebAppContext
How do I setup Jetty with Eclipse without plugin?
如何在没有插件的情况下使用Eclipse设置Jetty?
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
:
正如waxwing建议的那样,我应该更改类,因为它已从Jetty 6更改为Jetty 7.我再次启动Jetty服务器,现在我得到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:
我的sampleweb.xml放在我的Jetty项目的上下文目录中并且有这个内容,取自文章:
<?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.
我想设置一个简单的Hello World servlet。
2 个解决方案
#1
0
You need the jetty server adapter - look for install new server - which allow you to work with an unzipped jetty 6.
您需要jetty服务器适配器 - 寻找安装新服务器 - 它允许您使用解压缩的jetty 6。
#2
0
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.
该指南不完整,因为没有为您选择技术堆栈。一个空的web.xml应该可以正常运行 - 但它也不会由Jetty发布。换句话说,您的应用程序中有访问点。
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.
应该有很多对web.xml的引用。看这个例子。
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
.
另一方面,您可以使用类似Spring框架的东西,然后使用另一种方法,将Spring本身注册为servlet(或servlet侦听器)。请参阅官方文档中的此示例。还有很多其他Web框架都需要不同的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.
至于你的第二个问题,你使用的是Jetty 6吗?该指南是为Jetty 6编写的,因为类名已更改,因此不适用于较新版本。如果您使用的是Jetty 6,请考虑安装ThorbjørnRavnAndersen在其答案中建议的Jetty服务器适配器。
#1
0
You need the jetty server adapter - look for install new server - which allow you to work with an unzipped jetty 6.
您需要jetty服务器适配器 - 寻找安装新服务器 - 它允许您使用解压缩的jetty 6。
#2
0
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.
该指南不完整,因为没有为您选择技术堆栈。一个空的web.xml应该可以正常运行 - 但它也不会由Jetty发布。换句话说,您的应用程序中有访问点。
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.
应该有很多对web.xml的引用。看这个例子。
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
.
另一方面,您可以使用类似Spring框架的东西,然后使用另一种方法,将Spring本身注册为servlet(或servlet侦听器)。请参阅官方文档中的此示例。还有很多其他Web框架都需要不同的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.
至于你的第二个问题,你使用的是Jetty 6吗?该指南是为Jetty 6编写的,因为类名已更改,因此不适用于较新版本。如果您使用的是Jetty 6,请考虑安装ThorbjørnRavnAndersen在其答案中建议的Jetty服务器适配器。