tomcatインストール

$ wget http://ftp.kddilabs.jp/infosystems/apache/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.zip
$ unzip apache-tomcat-6.0.20.zip
$ mv apache-tomcat-6.0.20 /usr/local/
$ vi ~/.zshrc
export JAVA_HOME=/Library/Java/Home
export CATALINA_HOME=/usr/local/apache-tomcat-6.0.20
export CLASSPATH=.:$CATALINA_HOME/lib/servlet-api.jar:$CATALINA_HOME/lib/jsp-api.jar
$ source ~/.zshrc
$ sudo /usr/local/apache-tomcat-6.0.20/bin/startup.sh

Hello, Servlet!

$ cd /usr/local/apache-tomcat-6.0.20/webapps
$ mkdir -p hello-servlet/src hello-servlet/WEB-INF/classes
$ cd hello-servlet/src
$ vi HelloServlet.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class HelloServlet extends HttpServlet {
    public void service(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/plain");
        response.getWriter().println("Hello, Servlet!");
    }
}
$ javac HelloServlet.java
$ mv HelloServlet.class ../WEB-INF/classes

デプロイメントディスクリプタを書く。

$ vi /usr/local/apache-tomcat-6.0.20/conf/server.xml
(...)
      <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">   
        <Context path="/hello-servlet" docBase="hello-servlet" debug="0" reloadable="true" crossContext="true" />
(...)
      </Host>
(...)
$ vi /usr/local/apache-tomcat-6.0.20/webapps/hello-servlet/WEB-INF/web.xml
<?xml version="1.0" ?>
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <servlet>  
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
  </servlet>  
  <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/HelloServlet</url-pattern>
  </servlet-mapping>
</web-app>
HelloServlet

sudo port install tomcat6がこけるのが謎。

Comments


Option