天天看點

Eclipse配置JNDI連接配接池

之前用Eclipse JEE開發web工程,按照網上的一些說法,配置,發現很麻煩。而且每次project重新remove再加載,配置就丢失了。

根據tomcat使用的經驗,嘗試如下方法,就可以解決一次配置,所有同workspace的project都可以随時使用jdni了。

確定Eclipse中配置了tomcat runtime的情況下,在Eclipse中建立第一個web工程的時候,他會自動增加一個Tomcat Server工程,來維護一個tomcat容器,供你的工程來使用。

首先看一下project中的tomcat容器項目的清單:

Eclipse配置JNDI連接配接池

儲存如下内容為context.xml,增加到Server項目裡Tomcat v5.5 Server at localhost-config裡:

<?xml version="1.0" encoding="UTF-8"?>

<!--

  Licensed to the Apache Software Foundation (ASF) under one or more

  contributor license agreements.  See the NOTICE file distributed with

  this work for additional information regarding copyright ownership.

  The ASF licenses this file to You under the Apache License, Version 2.0

  (the "License"); you may not use this file except in compliance with

  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software

  distributed under the License is distributed on an "AS IS" BASIS,

  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

  See the License for the specific language governing permissions and

  limitations under the License.

-->

<!-- The contents of this file will be loaded for each web application -->

<Context>

    <!-- Default set of monitored resources -->

    <WatchedResource>WEB-INF/web.xml</WatchedResource>

    <!-- Uncomment this to disable session persistence across Tomcat restarts -->

    <!--

    <Manager pathname="" />

    -->

  <Resource auth="Container" driverClassName="oracle.jdbc.driver.OracleDriver" maxActive="30" maxIdle="5" maxWait="-1" name="jdbc/db02" password="pass" type="javax.sql.DataSource" url="jdbc:oracle:thin:@192.168.0.2:1521:myEntry" username="user"/> 

</Context>

測試一下吧,在這個workspace中建立一個web工程,運作,已經可以正常使用jdbc/db02拿到資料庫連接配接池了。