jetty Hello World示例未编译

时间:2011-03-10 19:13:19

标签: java webserver jetty javac

我正在尝试编译java类:http://wiki.eclipse.org/Jetty/Tutorial/Jetty_HelloWorld

使用Jetty网络服务。

出于某种原因,当我尝试跑步时:

javac -cp servlet-api-2.5.jar:jetty-all-$JETTY_VERSION.jar HelloWorld.java

它说有14个,是14个错误:

C:\Users\n...\DEMO>javac -cp servlet-api-2.5.jar:jetty-all-
7.3.0.v20110203.jar HelloWorld.java HelloWorld.java:1: package javax.servlet.http does not exist import javax.servlet.http.HttpServletRequest;
                         ^ HelloWorld.java:2: package javax.servlet.http does not exist import javax.servlet.http.HttpServletResponse;
                         ^ HelloWorld.java:3: package javax.servlet does not exist import javax.servlet.ServletException;
                    ^ HelloWorld.java:7: package org.eclipse.jetty.server does not exist import org.eclipse.jetty.server.Server;
                               ^ HelloWorld.java:8: package org.eclipse.jetty.server does not exist import org.eclipse.jetty.server.Request;
                               ^ HelloWorld.java:9: package org.eclipse.jetty.server.handler does not exist import org.eclipse.jetty.server.handler.AbstractHandler;
                                       ^ HelloWorld.java:11: cannot find symbol symbol: class AbstractHandler public class HelloWorld extends AbstractHandler
                                ^ HelloWorld.java:14: cannot find symbol symbol  : class Request location: class HelloWorld
                       Request baseRequest,
                       ^ HelloWorld.java:15: cannot find symbol symbol  : class HttpServletRequest location: class HelloWorld
                       HttpServletRequest request,
                       ^ HelloWorld.java:16: cannot find symbol symbol  : class HttpServletResponse location: class HelloWorld
                       HttpServletResponse response)
                       ^ HelloWorld.java:17: cannot find symbol symbol  : class ServletException location: class HelloWorld
        throws IOException, ServletException
                            ^ HelloWorld.java:20: cannot find symbol symbol  : variable HttpServletResponse location: class HelloWorld
        response.setStatus(HttpServletResponse.SC_OK);
                           ^ HelloWorld.java:27: cannot find symbol symbol  : class Server location: class HelloWorld
        Server server = new Server(8080);
        ^ HelloWorld.java:27: cannot find symbol symbol  : class Server location: class HelloWorld
        Server server = new Server(8080);
                            ^ 14 errors

How do i fix it so it works on my machine, and i can complie and run it?

Thanks.

UPDATE: HelloWorld.java (its on the site, but ill put it here):

import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.ServletException; import java.io.IOException; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.handler.AbstractHandler; public class HelloWorld extends AbstractHandler { public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { response.setContentType("text/html;charset=utf-8"); response.setStatus(HttpServletResponse.SC_OK); baseRequest.setHandled(true); response.getWriter().println("<h1>Hello World</h1>"); } public static void main(String[] args) throws Exception { Server server = new Server(8080); server.setHandler(new HelloWorld()); server.start(); server.join(); } }

更新2:

在安装JAVA EE SDK的过程中。 会告诉你它是否有效

2 个答案:

答案 0 :(得分:4)

在Windows上,你不应该使用';'而不是':'作为路径分隔符?

答案 1 :(得分:0)

我说你当前目录中没有jar文件C:\ Users \ n ... \ DEMO

尝试:

javac -cp C \: path \ to \ _ servlet-api-2.5.jar:C \: path \ to \ jetty-all- 7.3.0。 v20110203.jar HelloWorld.java

并替换路径......