레이블이 tomcat인 게시물을 표시합니다. 모든 게시물 표시
레이블이 tomcat인 게시물을 표시합니다. 모든 게시물 표시

2017년 9월 11일 월요일

apache tomcat jre requirements

http://tomcat.apache.org/whichversion.html


2011년 9월 1일 목요일

tomcat session timeout 변경

[tomcat]이 설치된 디렉토리/conf/web.xml 에서 아래 부분을 편집
단위는 분, 기본은 30분으로 설정되어 있음


<session-config>
        <session-timeout>360</session-timeout>
</session-config>

** 세션 타임아웃 적용 우선순위

1. 프로그램에 코딩된 session.setMaxInactiveInterval(int)
2. 각 웹 어플리케이션의 WEB-INF/web.xml
3. [tomcat설치디렉토리]/conf/web.xml

2011년 8월 2일 화요일

Tomcat JNDI Datasource 설정(MySQL)

출처: http://tomcat.apache.org/tomcat-6.0-doc/jndi-datasource-examples-howto.html


1. server.xml 파일에 resource 추가
(1) context 아래에 resource 추가하기
<Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true" crossContext="true">
  <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource"
               maxActive="100" maxIdle="30" maxWait="10000"
               username="javauser" password="javadude" driverClassName="com.mysql.jdbc.Driver"
               url="jdbc:mysql://localhost:3306/javatest"/></Context>

(2) GlobalNamingResources 에 추가
    <GlobalNamingResources>
        <Resource auth="Container" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
            name="UserDatabase" pathname="conf/tomcat-users.xml" type="org.apache.catalina.UserDatabase" />
        <Resource name="jdbc/TestDB" auth="Container" type="javax.sql.DataSource" 
            maxActive="100" maxIdle="30" maxWait="10000" username="javauser" password="javadude"
            driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/javatest" />
    </GlobalNamingResources>

...

<Context path="/DBTest" docBase="DBTest" debug="5" reloadable="true" crossContext="true">
  <ResourceLink global="jdbc/TestDB" name="jdbc/TestDB" type="javax.sql.DataSource"/>
</Context>


2. web.xml 파일 수정 
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">
  <description>MySQL Test App</description>
  <resource-ref>
      <description>DB Connection</description>

      <res-ref-name>jdbc/TestDB</res-ref-name>
      <res-type>javax.sql.DataSource</res-type>
      <res-auth>Container</res-auth>
      </resource-ref>
</web-app>


3. test.jsp  

<%@ page import="java.sql.*"%>
<%@ page import="javax.naming.*" %>
<%@ page import="javax.activation.*" %>
<%
    InitialContext cxt = new InitialContext();
    javax.sql.DataSource ds = null;
    Connection conn = null;
        if ( cxt == null ) {
       throw new Exception("Uh oh -- no context!");
    }
    ds = (javax.sql.DataSource) cxt.lookup( "java:/comp/env/jdbc/TestDB" );
    if ( ds == null ) {
       throw new Exception("Data source not found!");
    }
    conn = ds.getConnection();
    out.println(conn.getMetaData().getDriverVersion());
%>


Tomcat context 설정 (5.5 버전 이상)

Tomcat5.5 부터 Context 설정이 변경되었다.
이전 버전에서는 server.xml 에 저장되어는데 5.5 부터는 아래와 같은 방식으로 적용이 가능하다.

Context elements may be explicitly defined:
  • In the $CATALINA_BASE/conf/context.xml file: the Context element information will be loaded by all webapps.
  • In the $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file: the Context element information will be loaded by all webapps of that host.
  • In individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. foo#bar.xml for a context path of /foo/bar. The default web application may be defined by using a file called ROOT.xml.
  • Only if a context file does not exist for the application in the$CATALINA_BASE/conf/[enginename]/[hostname]/, in an individual file at /META-INF/context.xmlinside the application files. If the web application is packaged as a WAR then /META-INF/context.xml will be copied to $CATALINA_BASE/conf/[enginename]/[hostname]/ and renamed to match the application's context path. Once this file exists, it will not be replaced if a new WAR with a newer /META-INF/context.xml is placed in the host's appBase.
  • Inside a Host element in the main conf/server.xml.

참고: http://tomcat.apache.org/tomcat-6.0-doc/config/context.html

아래는 server.xml 에 host 관련 설정만 하고 context는 $CATALINA_BASE/conf/[enginename]/[hostname] 에 지정하는 방식으로 설정하는 방법이다.

1. server.xml 파일에 이전과 같은 방식으로 host 를 지정

      <Host name="localhost"  appBase="/some/host/path" unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
      </Host>

2. ROOT context 설정 ($CATALINA_BASE/conf/Catalina/localhost/ROOT.xml)
루트 컨텍스트 이름은 ROOT.xml 에 지정되야 한다.
Virtual Host를 적용해서 호스트명이 localhost가 아니라면 localhost를 해당 호스트 명으로 변경한다. (server.xml에서 지정한 이름)
<?xml version='1.0' encoding='utf-8'?>
<Context path="/board" docBase="/context/path/root/webapps" reloadable="true">

</Context>


3. 추가 context 설정 ($CATALINA_BASE/conf/Catalina/localhost/board.xml)

<?xml version='1.0' encoding='utf-8'?>
<Context path="/board" docBase="/context/path/board/webapps" reloadable="true">

</Context>