0

我有:

C:\jtty\WEB-INF\web.xml
           |
           |
         classes
           |------hello.war
           |------HelloWord.java
           |------HelloWord.class
           |------javax.servlet

首先我在 WEB-INF 文件夹中创建文件 web.xml:

<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
  <servlet>
    <servlet-name>HelloWorldServlet</servlet-name>
    <servlet-class>HelloWorld</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloWorldServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

然后,创建文件夹“classes”,并创建文件 HelloWord.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class HelloWorld extends HttpServlet {
  public void doGet(HttpServletRequest request,
    HttpServletResponse response)
    throws ServletException,IOException {
     response.setContentType("text/html");
     PrintWriter pw = response.getWriter();
     pw.println("<html><head><title>Hello World</title></title>");
     pw.println("<body><h1>Hello World</h1></body></html>");
  }
}

在 Windows 控制台中运行此命令:

C:\jtty\WEB-INF\classes>C:\Oracle\Java\jdk1.7.0\bin\javac -g -classpath ".;javax .servlet.jar" HelloWorld.java -verbose

之后 java-compiler 创建文件 HelloWord.class

此命令创建 hello.war

jar cvf hello.war 。

然后启动码头:

C:\jtty\WEB-INF\classes>C:\Oracle\Java\jdk1.7.0\bin\java -DDEBUG -jar c:\jetty-r
unner-7.0.0.RC2.jar hello.war
2012-09-25 10:23:37.765::INFO:  Logging to StdErrLog::DEBUG=false via org.eclips
e.jetty.util.log.StdErrLog
2012-09-25 10:23:37.765::INFO:  Runner
2012-09-25 10:23:37.765::DEBUG: Runner classpath []
2012-09-25 10:23:37.765::WARN:  No tx manager found
2012-09-25 10:23:37.796::DEBUG: Container org.eclipse.jetty.server.Server@428896
cf + HandlerCollection@15651229 as handler
2012-09-25 10:23:37.796::DEBUG: Container HandlerCollection@15651229 + ContextHa
ndlerCollection@5fc2ee8e as handler
2012-09-25 10:23:37.796::DEBUG: Container HandlerCollection@15651229 + DefaultHa
ndler@76bbddbf as handler
2012-09-25 10:23:37.796::DEBUG: Container HandlerCollection@15651229 + RequestLo
gHandler@28bf47df as handler
2012-09-25 10:23:37.812::DEBUG: Container org.eclipse.jetty.server.Server@428896
cf + SelectChannelConnector@0.0.0.0:8080 as connector
2012-09-25 10:23:37.828::DEBUG: Checking Resource aliases
2012-09-25 10:23:37.828::INFO:  Deploying file:/C:/jtty/WEB-INF/classes/hello.wa
r @ /
2012-09-25 10:23:37.843::DEBUG: Container ContextHandlerCollection@5fc2ee8e + We
bAppContext@6281635b@6281635b/,null as handler
2012-09-25 10:23:37.843::DEBUG: Container WebAppContext@6281635b@6281635b/,null,
file:/C:/jtty/WEB-INF/classes/hello.war + ErrorPageErrorHandler@32d9230a as erro
rHandler
[WebAppContext@6281635b@6281635b/,null,file:/C:/jtty/WEB-INF/classes/hello.war]
2012-09-25 10:23:37.843::DEBUG: Starting org.eclipse.jetty.server.Server@428896c
f
2012-09-25 10:23:37.843::INFO:  jetty-7.0.0.RC2
2012-09-25 10:23:37.859::DEBUG: Container org.eclipse.jetty.server.Server@428896
cf + qtp1533090852{8<=0<=0/254,-1} as threadpool
2012-09-25 10:23:37.859::DEBUG: Starting qtp1533090852{8<=0<=0/254,-1}
2012-09-25 10:23:37.859::DEBUG: STARTED qtp1533090852{8<=2<=8/254,0}
2012-09-25 10:23:37.859::DEBUG: Starting HandlerCollection@15651229
2012-09-25 10:23:37.875::DEBUG: Starting ContextHandlerCollection@5fc2ee8e
2012-09-25 10:23:37.875::DEBUG: Starting WebAppContext@6281635b@6281635b/,null,f
ile:/C:/jtty/WEB-INF/classes/hello.war
2012-09-25 10:23:37.875::DEBUG: Thread Context class loader is: ContextLoader@nu
ll([]) / sun.misc.Launcher$AppClassLoader@69adff28
2012-09-25 10:23:37.875::DEBUG: Parent class loader is: sun.misc.Launcher$AppCla
ssLoader@69adff28
2012-09-25 10:23:37.875::DEBUG: Parent class loader is: sun.misc.Launcher$ExtCla
ssLoader@1e4ad14c
2012-09-25 10:23:38.000::DEBUG: Set temp dir C:\temp\Jetty_0_0_0_0_8080_hello.wa
r____d40q3p
2012-09-25 10:23:38.109::DEBUG: Try webapp=file:/C:/jtty/WEB-INF/classes/hello.w
ar, exists=true, directory=false
2012-09-25 10:23:38.234::INFO:  Extract file:/C:/jtty/WEB-INF/classes/hello.war
to C:\temp\Jetty_0_0_0_0_8080_hello.war____d40q3p\webapp
2012-09-25 10:23:38.343::DEBUG: Extract jar:file:/C:/jtty/WEB-INF/classes/hello.
war!/ to C:\temp\Jetty_0_0_0_0_8080_hello.war____d40q3p\webapp
2012-09-25 10:23:38.453::DEBUG: Extracting entry = null from jar file:/C:/jtty/W
EB-INF/classes/hello.war
2012-09-25 10:23:38.593::DEBUG: webapp=file:/C:/temp/Jetty_0_0_0_0_8080_hello.wa
r____d40q3p/webapp/
**2012-09-25 10:23:38.718::WARN:  Failed startup of context WebAppContext@6281635b
@6281635b/,file:/C:/temp/Jetty_0_0_0_0_8080_hello.war____d40q3p/webapp/,file:/C:
/jtty/WEB-INF/classes/hello.war**
java.lang.NullPointerException
        at org.eclipse.jetty.webapp.WebInfConfiguration.findJars(WebInfConfigura
tion.java:588)
        at org.eclipse.jetty.webapp.WebInfConfiguration.preConfigure(WebInfConfi
guration.java:96)
        at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:339
)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLife
Cycle.java:56)
        at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCol
lection.java:164)
        at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(Con
textHandlerCollection.java:161)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLife
Cycle.java:56)
        at org.eclipse.jetty.server.handler.HandlerCollection.doStart(HandlerCol
lection.java:164)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLife
Cycle.java:56)
        at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrappe
r.java:92)
        at org.eclipse.jetty.server.Server.doStart(Server.java:232)
        at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLife
Cycle.java:56)
        at org.mortbay.jetty.runner.Runner.run(Runner.java:448)
        at org.mortbay.jetty.runner.Runner.main(Runner.java:587)
2012-09-25 10:23:40.390::DEBUG: STARTED WebAppContext@6281635b@6281635b/,file:/C
:/temp/Jetty_0_0_0_0_8080_hello.war____d40q3p/webapp/,file:/C:/jtty/WEB-INF/clas
ses/hello.war
2012-09-25 10:23:40.562::DEBUG: starting ContextHandlerCollection@5fc2ee8e
2012-09-25 10:23:40.625::DEBUG: STARTED ContextHandlerCollection@5fc2ee8e
2012-09-25 10:23:40.671::DEBUG: Starting DefaultHandler@76bbddbf
2012-09-25 10:23:40.734::DEBUG: starting DefaultHandler@76bbddbf
2012-09-25 10:23:40.796::DEBUG: STARTED DefaultHandler@76bbddbf
2012-09-25 10:23:40.843::DEBUG: Starting RequestLogHandler@28bf47df
2012-09-25 10:23:40.906::DEBUG: starting RequestLogHandler@28bf47df
2012-09-25 10:23:40.968::DEBUG: STARTED RequestLogHandler@28bf47df
2012-09-25 10:23:41.031::DEBUG: starting HandlerCollection@15651229
2012-09-25 10:23:41.078::DEBUG: STARTED HandlerCollection@15651229
2012-09-25 10:23:41.140::DEBUG: starting org.eclipse.jetty.server.Server@428896c
f
2012-09-25 10:23:41.265::DEBUG: Starting SelectChannelConnector@0.0.0.0:8080
2012-09-25 10:23:41.312::DEBUG: Starting org.eclipse.jetty.server.nio.SelectChan
nelConnector$1@29acfd6
2012-09-25 10:23:41.468::DEBUG: STARTED org.eclipse.jetty.server.nio.SelectChann
elConnector$1@29acfd6
2012-09-25 10:23:41.593::INFO:  Started SelectChannelConnector@0.0.0.0:8080
2012-09-25 10:23:41.640::DEBUG: STARTED SelectChannelConnector@0.0.0.0:8080
2012-09-25 10:23:41.703::DEBUG: org.eclipse.jetty.server.Server@428896cf STOPPED

 +-HandlerCollection@15651229 started
    +-ContextHandlerCollection@5fc2ee8e started
    |  **+-WebAppContext@6281635b@6281635b/,file:/C:/temp/Jetty_0_0_0_0_8080_hello
.war____d40q3p/webapp/,file:/C:/jtty/WEB-INF/classes/hello.war started
    |     +-null**
    +-DefaultHandler@76bbddbf started
    +-RequestLogHandler@28bf47df started
       +-null

2012-09-25 10:23:42.343::DEBUG: STARTED org.eclipse.jetty.server.Server@428896cf

最后我看到了这个:

http://xxx.xxx.xxx.xxx:8080/

HTTP 错误:503

访问 / 时出现问题。原因:

Service Unavailable

由码头提供支持://

在控制台日志中:

2012-09-25 10:31:22.359::DEBUG: REQUEST / on org.eclipse.jetty.server.nio.Select ChannelConnector$2@77e8a5c 2012-09-25 10:31:22.406::DEBUG: RESPONSE / 503

4

1 回答 1

1

尝试更新版本的 jetty-runner,或者尝试使用 jetty-distribution,7.0.0.RC2 是旧的并且在 jetty-runner 创建的早期,我们刚刚发布了 7.6.7.v20120910

于 2012-09-26T03:44:42.330 回答