Tomcat 4.1 ROOT directory

kenu
2002-09-09 12:14오전

이번 강좌는 Tomcat 4.1.10 버전의 디렉토리를 변경하는 것입니다. Tomcat 4.0 버전의 경우 크게 차이가 없이 동일하게 적용하시면 될 것입니다. Tomcat 3 에서 ROOT 를 바꾸는 것과는 차이가 있습니다. 하지만 알고 보면 별 것 없습니다. 이번 강좌에서 알아 볼 것은 다음과 같습니다.
Tomcat 4.1 디렉토리
최초 설치시 파일의 위치
컨텍스트 추가하기
ROOT 디렉토리 변경하기

		


ROOT 디렉토리 변경을 마지막으로 뺀 이유는 이렇게 하는 것이 크게 의미가 없기 때문입니다. Tomcat 환경이 익숙해져서이겠지요. 처음 Tomcat을 시작했을 때는 왜이리 디렉토리가 쳐박혀 있나 싶었는데, 이제는 바꾸는 일이 더 일처럼 생각이 되네요. ^^; Tomcat 의 디렉토리에 대해서 살펴보기로 하겠습니다. 

Tomcat 4.1 을 처음 설치했을 때 디렉토리구조는 다음과 같습니다. Tomcat 4.1 이 설치된 디렉토리의 webapps 디렉토리 아래에 ROOT 가 jsp, html, 등의 파일들이 놓이는 위치입니다. 

ROOT 아래에 있는 WEB-INF 디렉토리는 ROOT 컨텍스트에 대한 정보를 담고 있는 web.xml 이라는 deploy descriptor 파일이 있습니다. 또한 서블릿과 빈즈, 이 컨텍스트에서만 사용되는 jar 파일들이 서브디렉토리에 위치하게 됩니다. servlet과 beans 그리고 helper class 들과 같은 class 파일들과 properties 파일들은 WEB-INF/classes 디렉토리에 위치하게 됩니다. jdbc driver 등의 jar 파일들은 WEB-INF/lib 디렉토리에 놓습니다. 처음 설치를 하면 이 두개의 디렉토리는 보이지 않습니다. 그렇다면 만들면 됩니다. 테스트를 위해서 examples/WEB-INF/classes 아래에 있는 HelloWorldExample.class 서블릿 파일을 ROOT/WEB-INF/classes 아래에 복사해 봅니다. 이때 주의할 것은 HelloWorldExample.java 서블릿 소스를 보시면 LocalStrings 라는 properties 파일을 필요로 한다는 것을 알 수 있습니다. 따라서 LocalStrings.properties 파일이 없다면 에러가 나오게 됩니다. 같이 복사를 한 뒤에 Tomcat 4.1 을 재시동해서 브라우저에서 http://localhost:8080/servlet/HelloWorldExample 주소로 확인해봅니다. 

Context is a web application. 이라고 했습니다. 하나의 컨텍스트를 추가하는 것은 웹 어플리케이션을 하나를 추가하는 것입니다. Tomcat4.1 의 conf 디렉토리에 있는 server.xml 파일을 텍스트편집기로 엽니다. 아래 부분을 파일에서 찾아보십시오. Tomcat 의 Root 컨텍스트는 주석으로 감싸져있고, 그 아래에 /examples 컨텍스트가 보입니다. docBase 는 하드 디스크상의 경로명이고, 해당 Host 의 appBase(="webapps") 에 대해 상대 경로 입니다.
conf/servlet.xml
...

        <!-- Define properties for each web application.  This is only needed
             if you want to set non-default properties, or have web application
             document roots in places other than the virtual host's appBase
             directory.  -->

        <!-- Tomcat Root Context -->
        <!--
          <Context path="" docBase="ROOT" debug="0"/>
        -->

        <!-- Tomcat Examples Context -->
        <Context path="/examples" docBase="examples" debug="0"
                 reloadable="true" crossContext="true">
          <Logger className="org.apache.catalina.logger.FileLogger"
                     prefix="localhost_examples_log." suffix=".txt"
        	  timestamp="true"/>
...

		


okjsp 라는 컨텍스트를 추가해 보겠습니다. c: 드라이브에 okjsp 디렉토리를 만듭니다. 이곳을 새로운 컨텍스트의 Root 디렉토리로 정합니다. 주의할 점은 <Context> 태그는 xml 의 문법을 준수 하여야 되기 때문에 <Context ... /> 와 같이 단독태그로 끝을 닫아주거나 <Context ....></Context> 로 막아주어야 됩니다. Tomcat 을 재시동합니다. reloadable 이라는 속성은 servlet reloading 에 관한 속성입니다.
conf/servlet.xml
...

        <!-- Define properties for each web application.  This is only needed
             if you want to set non-default properties, or have web application
             document roots in places other than the virtual host's appBase
             directory.  -->

        <!-- Tomcat Root Context -->
        <!--
          <Context path="" docBase="ROOT" debug="0"/>
        -->

        <!-- Tomcat okjsp Context -->
        <Context path="/okjsp" docBase="c:/okjsp" debug="0"
                 reloadable="true"/>

        <!-- Tomcat Examples Context -->
        <Context path="/examples" docBase="examples" debug="0"
                 reloadable="true" crossContext="true">
          <Logger className="org.apache.catalina.logger.FileLogger"
                     prefix="localhost_examples_log." suffix=".txt"
        	  timestamp="true"/>
...

		


다음 파일을 c:\okjsp 디렉토리에 넣고 브라우저에서 호출해봅니다. 새로운 컨텍스트에 servlet 을 복사하고 브라우저에서 불러봅니다. 루트컨텍스트의 WEB-INF/ 아래있는 모든 파일과 디렉토리를 c:/okjsp/WEB-INF/ 에 복사한 뒤에 브라우저에서 주소를 http://localhost:8080/okjsp/servlet/HelloWorldExample 로 호출하면 됩니다.
realpath.jsp
<%=request.getRealPath("/") %>

		


이제는 ROOT 디렉토리를 바꾸는 작업을 해보겠습니다. Tomcat4.1 의 conf 디렉토리에 있는 server.xml 파일을 텍스트편집기로 엽니다. 아래 부분을 파일에서 찾아보십시오. 주석 부분을 읽어보시면 아시겠지만, 웹 어플리케이션 기본 설정을 변경하기 원하면 바꾸라고 되어있습니다.
conf/servlet.xml
...

        <!-- Define properties for each web application.  This is only needed
             if you want to set non-default properties, or have web application
             document roots in places other than the virtual host's appBase
             directory.  -->

        <!-- Tomcat Root Context -->
        <!--
          <Context path="" docBase="ROOT" debug="0"/>
        -->

        <!-- Tomcat Examples Context -->
        <Context path="/examples" docBase="examples" debug="0"
                 reloadable="true" crossContext="true">
          <Logger className="org.apache.catalina.logger.FileLogger"
                     prefix="localhost_examples_log." suffix=".txt"
        	  timestamp="true"/>
...

		


c: 드라이브의 jsphome 이라는 디렉토리를 ROOT로 잡아보도록 하겠습니다. ( 아주 오랜만입니다. ^^) c:\jsphome 디렉토리를 만든 후에 아래처럼 변경합니다. C:/jsphome 에서 디렉토리 구분표시는 ms 의 \ 가 아니라 unix 스타일인 /(슬래시) 표시를 합니다. 이 아래에 WEB-INF 디렉토리를 만들고 web.xml 파일을 복사해 놓습니다. 그리고 classes 디렉토리와 lib 디렉토리를 만들어 놓고, tomcat 을 재시동합니다. 이제 ROOT 를 바꾸는 설정법은 끝났습니다. 한가지 속성을 설명하려합니다. reloadable="true" 라는 속성입니다. servlet 이 변경되었을 경우 이 Context 전체를 다시 불러오도록 하는 속성입니다. 개발중에는 "true" 라는 속성으로 개발완료 후에는 "false" 로 하시는 것이 성능면에서 도움이 됩니다. servlet reloading 은 파일의 갱신날짜를 비교하기 때문입니다.
conf/servlet.xml
...

        <!-- Define properties for each web application.  This is only needed
             if you want to set non-default properties, or have web application
             document roots in places other than the virtual host's appBase
             directory.  -->

        <!-- Tomcat Root Context -->
          <Context path="" docBase="C:/jsphome" debug="0" reloadable="true" />

        <!-- Tomcat Examples Context -->
        <Context path="/examples" docBase="examples" debug="0"
                 reloadable="true" crossContext="true">
          <Logger className="org.apache.catalina.logger.FileLogger"
                     prefix="localhost_examples_log." suffix=".txt"
        	  timestamp="true"/>
...

		


설정이 다 끝났으면 톰캣을 재시동하고, 브라우저에서 위에 있는 realpath.jsp 파일을 호출해서 확인해봅니다. 

관련 사이트
http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/context.html 
Tomcat 4.1 Context 문서
http://210.219.132.169/bbs?act=VIEW&bbs=bbs4&seq=23530 
Tomcat 4.1.12 버전에서 서블릿 접근이 안되는 경우


Posted by linuxism
,