jetty配置jndi數據源


1.下載jetty服務器(8.1.0.RC2),解壓到任意目錄下

  http://dist.codehaus.org/jetty/jetty-hightide-8.1.0/jetty-hightide-8.1.0.RC2.zip

2.新建jetty-dataSource.xml文件,放在${JETTY_HOME}\contexts目錄下

這個例子新建了兩個mysql數據源,

<?xml version="1.0"  encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!-- ==================================================================
Configure and deploy the test web application in $(jetty.home)/webapps/test

Note. If this file did not exist or used a context path other that /test
then the default configuration of jetty.xml would discover the test
webapplication with a WebAppDeployer.  By specifying a context in this
directory, additional configuration may be specified and hot deployments 
detected.
===================================================================== -->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
	<Set name="contextPath">/datasource</Set>
	<Set name="resourceBase">./</Set>
	<New id="showcase" class="org.eclipse.jetty.plus.jndi.Resource">
		<Arg></Arg>
		<Arg>jdbc/showcase</Arg>
		<Arg>
			<New class="com.mchange.v2.c3p0.ComboPooledDataSource">
				<Set name="driverClass">com.mysql.jdbc.Driver</Set>
				<Set name="jdbcUrl">jdbc:mysql://localhost:3306/showcase?useUnicode=true&characterEncoding=UTF8</Set>
				<Set name="user">root</Set>
				<Set name="password">111111</Set>
			</New>
		</Arg>
    </New>
	
	<New id="quartz" class="org.eclipse.jetty.plus.jndi.Resource">
		<Arg></Arg>
		<Arg>jdbc/quartz</Arg>
		<Arg>
			<New class="com.mchange.v2.c3p0.ComboPooledDataSource">
				<Set name="driverClass">com.mysql.jdbc.Driver</Set>
				<Set name="jdbcUrl">jdbc:mysql://localhost:3306/quartz?useUnicode=true&characterEncoding=UTF8</Set>
				<Set name="user">root</Set>
				<Set name="password">111111</Set>
			</New>
		</Arg>
    </New>
</Configure>
3.將數據源用到的jar包放到${JETTY_HOME}\lib\ext目錄下

因為以上用到了c3p0數據庫連接池和mysql數據庫,因此需要將mysql-connector-java-5.1.17.jar和c3p0-0.9.1.2.jar放到jetty容器的lib中

4.重啟jetty容器

  命令行到${JETTY_HOME}目錄下,運行 java -jar start.jar啟動容器

5.附:常見的jndi數據庫鏈接池配置

參考:http://wiki.eclipse.org/Jetty/Howto/Configure_JNDI_Datasource



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM