关于在jbuilder中使用jndi配置datasource(tomcat4、jbuilder9-x)

类别:Java 点击:0 评论:0 推荐:

最近在做一个项目使用到tomcat里的datasource,因为要在jbuilder中调试启动tomcat,配置这个是一个问题,因为当你建立一个工程,一些配置文件在运行期才会产生;
    例如:新建一个工程-TestDemo,启动tomcat时会在工程目录下的tomcat/conf/ 产生server808X.xml临时文件(根据端口不同产生),同时会在工程目录下的tomcat/webapp/下产生jb--TestDemo.xml临时文件(当然是依据工程名产生的),并同时加载这两个文件,还要加载一个工程目录下的tomcat/webapp/jb--default.xml。
 你的配置选项必须写在server808x.xml文件中;
 自动产生如下:
server8080.xml:

 <?xml version="1.0" encoding="UTF-8"?>
<!--This comment marks this file as generated, so it may be deleted and regenerated at any time. To preserve manual changes to this file, delete this comment.-->
<Server debug="0" port="8081" shutdown="SHUTDOWN">
  <Service name="Tomcat-Standalone">
    <Connector acceptCount="10" className="org.apache.coyote.tomcat4.CoyoteConnector" connectionTimeout="60000" debug="0" maxProcessors="75" minProcessors="5" port="8080"/>
    <Engine debug="0" defaultHost="localhost" name="Standalone">
      <Host appBase="F:\TestDemo\Tomcat\webapps" debug="0" name="localhost" unpackWARs="true"/>
    </Engine>
  </Service>
</Server>


文档写的很清楚,你要手动配置,请把注释删除既可(这样就不自动产生了,也不会删除),
现在我们要把配置参数写到这里面:写好的文件如下:

<?xml version="1.0" encoding="UTF-8"?>
<Server debug="0" port="8081" shutdown="SHUTDOWN">
  <Service name="Tomcat-Standalone">
    <Connector acceptCount="10" className="org.apache.coyote.tomcat4.CoyoteConnector" connectionTimeout="60000" debug="0" maxProcessors="75" minProcessors="5" port="8080"/>
    <Engine debug="0" defaultHost="localhost" name="Standalone">
      <DefaultContext>
        <Resource auth="Container" name="jdbc/achieve" type="javax.sql.DataSource"/>
        <ResourceParams name="jdbc/achieve">
          <parameter>
            <name>factory</name>
            <value>org.apache.commons.dbcp.BasicDataSourceFactory</value>
          </parameter>
          <parameter>
            <name>driverClassName</name>
            <value>com.microsoft.jdbc.sqlserver.SQLServerDriver</value>
          </parameter>
          <parameter>
            <name>url</name>
            <value>jdbc:microsoft:sqlserver://192.9.100.252:1433;databasename=achievement</value>
          </parameter>
          <parameter>
            <name>username</name>
            <value>sa</value>
          </parameter>
          <parameter>
            <name>password</name>
            <value>sa</value>
          </parameter>
          <parameter>
            <name>maxActive</name>
            <value>30</value>
          </parameter>
          <parameter>
            <name>maxIdle</name>
            <value>10</value>
          </parameter>
          <parameter>
            <name>maxWait</name>
            <value>10000</value>
          </parameter>
        </ResourceParams>
      </DefaultContext>
      <Host appBase="F:\TestDemo\Tomcat\webapps" debug="0" name="localhost" unpackWARs="true"/>
    </Engine>
  </Service>
</Server>

然后保存,在jbuilder 中run,可以使用jndi找到datasource了!!!!

本文地址:http://com.8s8s.com/it/it11910.htm