系列1:was8.5.5 liberty profile hello world servlet3

我的was安装在C:\IBM\was855nalp, 使用<wlp_home>表示
1)创建server
进入<wlp_home>/bin
运行命令server create simpleServer
结果: <wlp_home>/usr/servers/simpleServer被创建

2-1使用dropin方式
cd 到<wlp_home>\usr\servers\simpleServer\dropins
mkdir -p helloworld.war/WEB-INF/classes/test
vi HelloServlet.java
package test;

import javax.servlet.annotation.WebServlet;

@WebServlet("/HelloServlet")
public class HelloServlet extends HttpServlet {
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.getWriter().println("hello world");
	}

}



编译(依赖servlet.jar)

javac -cp C:\IBM\was855nalp\dev\api\spec\com.ibm.ws.javaee.servlet.3.0_1.0.1.jar HelloServlet.java
在当前目录下生成了HelloServlet.class文件(servlet3.0不需要web.xml)

接下来启动simpleServer
cd <wlp_home>/bin
server run simpleServer(前台运行)
或server start simpleServer(后台运行)

打印出如下内容
C:\IBM\was855nalp\bin>server run simpleServer
Launching simpleServer (WebSphere Application Server 2014.2.0.0/wlp-1.0.3.20140221-0230) on Java HotSpot(TM) 64-Bit Server VM, ver
sion 1.7.0_51-b13 (en_US)
[AUDIT   ] CWWKE0001I: The server simpleServer has been launched.
[AUDIT   ] CWWKZ0058I: Monitoring dropins for applications.
[AUDIT   ] CWWKT0016I: Web application available (default_host): http://localhost:9080/helloworld/
[AUDIT   ] CWWKZ0001I: Application helloworld started in 0.628 seconds.
[AUDIT   ] CWWKF0011I: The server simpleServer is ready to run a smarter planet.

测试: 在浏览器中访问:http://localhost:9080/helloworld/HelloServlet

2-2 server.xml中注册application的方式
把dropins中的helloworld.war目录移动到<wlp_home>\usr\servers\simpleServer\apps

修改默认生成的server.xml的内容如下:

<server description="new server">

    <!-- Enable features -->
    <featureManager>
        <feature>servlet-3.0</feature>
    </featureManager>

	<webApplication name="helloworld" location="helloworld.war"/>
	
    <httpEndpoint id="defaultHttpEndpoint"
                  host="localhost"
                  httpPort="9080"
                  httpsPort="9443" />
</server>



以2-1相同的方式启动simpleServer并测试

你可能感兴趣的:(系列1:was8.5.5 liberty profile hello world servlet3)