Tomcat 6: basic configuration

JNDI DataSource

設定 tomcat/conf/server.xml (以下設定為資料庫使用 MySQL)

<GlobalNamingResources>
    <Resource auth="Container"
        factory="org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory"
        driverClassName="com.mysql.jdbc.Driver"
        maxActive="50" maxIdle="0" maxWait="-1"
        name="jdbc/mydatasource" type="javax.sql.DataSource"
        username="root" password=""
        url="jdbc:mysql://localhost:3306/testdb?characterEncoding=utf8&useUnicode=true"
    />
</GlobalNamingResources>

設定 tomcat/conf/context.xml

<Context>
    <ResourceLink name="jdbc/mydatasource" global="jdbc/mydatasource" type="javax.sql.DataSource"/>
</Context>

建立 Tomcat admin user

<tomcat-users>
    <role rolename="manager"/>
    <user username="admin" password="secret" roles="manager"/>
</tomcat-users>

在 Eclipse 內建立 TomcatServer 注意事項

若是在 Eclipse 內建立 Tomcat Server, 且 Tomcat Server 的 Location 設定為 “Use Tomcat Installation”, 就要注意 Eclipse 會自動將 Tomcat Server 的 server.xml, content.xml …等檔案將複製至 Tomcat Installation folder 內,因此會將原始檔案覆蓋, 所以這個時候要修改的是 Eclipse 裡 TomcatServer 的 configuration file。

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s