开发者

jetty Hello World Example not compiling

I am trying to compile the java class on: http://wiki.eclipse.org/Jetty/Tutorial/Jetty_HelloWorld

with Jetty web service.

For some reason when i try running:

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

It says there are 14, yes 14 errors:

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(); } }

UPDATE 2:

In the process of installing JAVA EE SDK. Will let you 开发者_高级运维know if it works


On Windows, aren't you supposed to use ';' instead of ':' as a path separator?


i'd say you dont have the jar files in your current directory C:\Users\n...\DEMO

try:

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

and replace the paths...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜