在 Eclipse 中运行 Jetty 7 服务器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2415803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running Jetty 7 server in eclipse?
提问by user264636
I'm trying to set up Eclipse to run and deploy my projects to a Jetty 7 server (the oldest version available from http://download.eclipse.org/jetty/). I've downloaded Jetty 7 and unpacked it, and I've installed the Jetty plugin from the available server adapters list, but when I try to configure a new Jetty server, the server type list only contains "Jetty 6". If I use this and point it at my server runtime, when I try to start it I get the following error:
我正在尝试设置 Eclipse 来运行我的项目并将其部署到 Jetty 7 服务器(可从http://download.eclipse.org/jetty/ 获得的最旧版本)。我已经下载了 Jetty 7 并解压了它,并且我已经从可用的服务器适配器列表中安装了 Jetty 插件,但是当我尝试配置一个新的 Jetty 服务器时,服务器类型列表只包含“Jetty 6”。如果我使用它并将其指向我的服务器运行时,当我尝试启动它时,我会收到以下错误:
java.lang.NoClassDefFoundError: org/mortbay/start/Main Caused by: java.lang.ClassNotFoundException: org.mortbay.start.Main at java.net.URLClassLoader.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) at java.lang.ClassLoader.loadClassInternal(Unknown Source) Exception in thread "main"
I'm guessing I need a different adaptor to start Jetty 7, but I have no idea where to find it.
我猜我需要一个不同的适配器来启动 Jetty 7,但我不知道在哪里可以找到它。
采纳答案by Thorbj?rn Ravn Andersen
The problem is that the package name changed with the migration to Eclipse, and the Jetty folks are still busy.
问题是包名随着迁移到 Eclipse 发生了变化,Jetty 的人还在忙。
Your easiest option is to download Jetty 6 from Codehaus (http://dist.codehaus.org/jetty/), unpack it somewhere and use the Jetty 6 adapter.
最简单的选择是从 Codehaus ( http://dist.codehaus.org/jetty/)下载 Jetty 6 ,在某处解压并使用 Jetty 6 适配器。
回答by Dimas Kotvan
Better than using the WTP adapters I prefer to use an embedded jetty. I just create a regular java project, let's call "embedded-jetty". I make the original webapp project a requirement to this project in the Projects section of the Java Build Path of the project properties. Than I create a class that start a jetty instance like this:
比使用 WTP 适配器更好,我更喜欢使用嵌入式码头。我只是创建了一个常规的 Java 项目,我们称之为“嵌入式码头”。我在项目属性的 Java Build Path 的 Projects 部分将原始 webapp 项目作为该项目的要求。比我创建一个类来启动一个像这样的码头实例:
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.webapp.WebAppContext;
public class JettyServer {
public static void main(String[] args) {
Server server = new Server(8080);
WebAppContext context = new WebAppContext();
context.setResourceBase("../webapp-project/WebContent");
context.setDescriptor("../webapp-project/WebContent/WEB-INF/web.xml");
context.setContextPath("/");
context.setParentLoaderPriority(true);
server.setHandler(context);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
}
On the embedded-jetty project I create a "lib" folder and copy all the libs from the jetty/lib folder, then I add the libs on the Libraries of the project properties.
在嵌入式码头项目中,我创建了一个“lib”文件夹并从 jetty/lib 文件夹复制所有库,然后在项目属性的库中添加库。
Running and debugging the jetty embedded works great for me, the jsp and class reloading works like a charm
运行和调试嵌入的码头对我来说非常有用,jsp 和类重新加载就像一个魅力
回答by Thomas Broyer
There's a new (official!) Jetty WTP Plugin supporting Jetty 7.x and 8.x: http://wiki.eclipse.org/Jetty_WTP_Plugin
有一个新的(官方!)Jetty WTP 插件支持 Jetty 7.x 和 8.x:http: //wiki.eclipse.org/Jetty_WTP_Plugin
回答by TonyQ
Run-Jetty-Run Eclipse plug-in have well support for both Jetty7 and Jetty 8 , and easier to use then WTP Eclipse for me .
Run-Jetty-Run Eclipse插件对Jetty7和Jetty 8都有很好的支持,对我来说比WTP Eclipse更容易使用。
It's worth to try it. :)
值得一试。:)
回答by Lucky
You can use the Jetty Maven Plugin to configure jetty server in your eclipse very easily. Include the following elements in you pom.xml
您可以使用 Jetty Maven 插件非常轻松地在 Eclipse 中配置 jetty 服务器。在您中包含以下元素pom.xml
<jetty.version>9.3.0.M1</jetty.version>
<!-- JETTY DEPENDENCIES -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlet</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
<version>${jetty.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-ant</artifactId>
<version>${jetty.version}</version>
</dependency>
and in your pom's plugins managements,
在你的 pom 插件管理中,
<plugin>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty.version}</version>
<configuration>
<stopKey>keyStop</stopKey>
<stopPort>8181</stopPort>
<httpConnector>
<host>0.0.0.0</host> //also localhost or IP address
<port>8080</port>
</httpConnector>
</configuration>
</plugin>
Or you could separate out the server configuration in separate jetty-.xml
files. See Configuring the jetty containerfor more.
或者您可以在单独的jetty-.xml
文件中分离服务器配置。有关更多信息,请参阅配置 jetty 容器。
Now right click your maven project and run the goal,
现在右键单击您的 Maven 项目并运行目标,
mvn jetty:run
to start the server on default port 8080. And to stop the server,
在默认端口 8080 上启动服务器。并停止服务器,
mvn jetty:stop
If not specified, Jetty will create a ServerConnector instance listening on port
8080
. You can change this default port number by using the system propertyjetty.http.port
on the command line, for example,mvn -Djetty.http.port=9999 jetty:run
. Note that since jetty-9.0 it is no longer possible to configure a https connector directly in the pom.xml: you need to use jetty xml config files to do it.
如果未指定,Jetty 将创建一个侦听端口的 ServerConnector 实例
8080
。您可以使用jetty.http.port
命令行上的系统属性更改此默认端口号,例如,mvn -Djetty.http.port=9999 jetty:run
。请注意,从 jetty-9.0 开始,不再可能直接在 pom.xml 中配置 https 连接器:您需要使用 jetty xml 配置文件来执行此操作。
Read about more goals and configuration on jetty site,
在 jetty 网站上阅读更多目标和配置,