`

JBoss 7.1 - Datasource Configuration and App Deployment

阅读更多
JBoss 7.1.1.Final has been released in 3月份 2012. Lets take a look at its directories, how to deploy and how to configure data source.

1. Directory Layout: JBoss 7 is fundamentally different from previous releases. It's module based and has a new directory layout. My understanding is that it has a "smaller" core and lots of stuff are configured as extensions/modules.

The following is the screen shot of its directories:



2. Standalone/Domain Server Confiurations: JBoss 7 has two server "configurations", the "domain" and "standalone". The "domain" configuration provides a means to manage multiple JBoss instances (probably) running on difference servers. The "standalone" configuration is similar to previous "default" configurations in JBoss 4/5/6. So lets take a look at the "standalone" configuration.

The main conf file is "JBOSS_HOME/standalone/configuration/standalone.xml"

The deployment place is "JBOSS_HOME/standalone/deployments".

To deploy an application, you can just drop the application archive (ear or war) to the above dir, or you can use the CLI(Command Line Interface) instead. After deployed, depends on the status, you've got a "your-app-archive-name.deployed" or ""your-app-archive-name.failed" mark file, as following screen shot shows:




3. Configure data source for JBoss 7.1.1

Two steps to configure a datasource for JBoss 7.1, to deploy a jdbc driver and to add the datasource entry in the server conf file.

There're many ways to deploy the jdbc driver. This article finds two ways handy: as deploying the jdbc driver directly OR as a module. Takeing oracle for instace:

3.1.1 Deploying the jdbc driver directly

This requires that the jdbc driver conforms to the jdbc4 spec. That is, the jdbc jar must contain a file "META-INF\services\java.sql.Driver". It is a text file and contains only one line, which is the driver class name. For instance "oracle.jdbc.OracleDriver" for Oracle driver "ojdbc6.jar".

Deploying is simple, just drop the jdbc driver jar file to "deployments" and it's done.

3.1.2 To configure a datasource: to use the deployed jdbc driver, you need to edit "standalone/configuration/standalone.xml", ie, the "datasource" section. It already has an example entry there. The only thing need to take care is the content of the <driver/> element: is has to match the jar file name "ojdbc6.jar". If you have a long jar name, like "mysql-abc-blah-5_15.jar", it has to be "mysql-abc-blah-5_15.jar". The following is the entry for this Oracle data source:

<subsystem xmlns="urn:jboss:domain:datasources:1.0">
	<datasources>
	    <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
		    <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
		    <driver>h2</driver>
		    <security>
		        <user-name>sa</user-name>
		        <password>sa</password>
		    </security>
	    </datasource>
		<datasource jta="true" jndi-name="java:/ProJee6DS" pool-name="ProJee6DS" enabled="true" use-java-context="true">
			<connection-url>jdbc:oracle:thin:@127.0.0.1:1521:jwTestOra</connection-url>
                    <!-- driver name must match jdbc jar file name -->
			<driver>ojdbc6.jar</driver>
			<pool>
				<min-pool-size>5</min-pool-size>
				<max-pool-size>10</max-pool-size>
			</pool>
			<security>
				<user-name>jwtest</user-name>
				<password>jwtest</password>
			</security>
			<timeout>
				<blocking-timeout-millis>30000</blocking-timeout-millis>
			</timeout>
			<statement>
				<prepared-statement-cache-size>100</prepared-statement-cache-size>
			</statement>
		</datasource>
		<drivers>
			<driver name="h2" module="com.h2database.h2">
				<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
			</driver>
		</drivers>
	</datasources>
</subsystem>


One should pay attention to the sequence of the elements, it's not random and controlled by the schema. For anyone familiar with XSDs, you may want to take a look at the datasource schema and figure out what elements are available and in what sequence. These are available under this folder: "JBOSS_HOME/docs/jboss-as-datasources_1_0.xsd".

3.2 Deploying the jdbc driver as a module
Now take a look at the alternative way of configure a data source for the JBoss 7.1.1. JBoss seems to promote the direct jdbc driver deployment, but some jdbc drivers are missing the text file "META-INF\services\java.sql.Driver". Although one can manually add this simple text file to the jdbc driver jar file, a preferable approach is to deploy the jdbc driver as a module, as the following describes:

step1: create folder "JBOSS_HOME/modules/com/oracle/main"
step2: copy the jdbc driver "ojdbc6.jar" to the folder just created in step1.
step3: create an xml file "module.xml" in the folder just created in step1. Following is the content of this xml file:
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="com.oracle">
    <resources>
        <resource-root path="ojdbc6.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
        <module name="javax.servlet.api" optional="true"/>
    </dependencies>
</module>


The screen shot of folder "JBOSS_HOME/modules/com/oracle/main":



3.2.2 Configure the datasource
OK, now the jdbc driver has been configured as a module. We can configure a datasource to using the new module, again by editing the entry in file "standalone/configuration/standalone.xml". It's necessary to add a "<driver/>" which references the configured module for the jdbc driver.

<subsystem xmlns="urn:jboss:domain:datasources:1.0">
	<datasources>
		<datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="ExampleDS" enabled="true" use-java-context="true">
	        <connection-url>jdbc:h2:mem:test;DB_CLOSE_DELAY=-1</connection-url>
	        <driver>h2</driver>
	        <security>
	            <user-name>sa</user-name>
	            <password>sa</password>
	        </security>
	    </datasource>
	    <datasource jta="true" jndi-name="java:/ProJee6DS" pool-name="ProJee6DS" enabled="true" use-java-context="true">
	        <connection-url>jdbc:oracle:thin:@127.0.0.1:1521:jwTestOra</connection-url>
	        <driver>jwOracle</driver>
	        <pool>
	            <min-pool-size>5</min-pool-size>
	            <max-pool-size>10</max-pool-size>
	        </pool>
	        <security>
	            <user-name>jwtest</user-name>
	            <password>jwtest</password>
	        </security>
	        <timeout>
	            <blocking-timeout-millis>30000</blocking-timeout-millis>
	        </timeout>
	        <statement>
	            <prepared-statement-cache-size>100</prepared-statement-cache-size>
	        </statement>
	    </datasource>
	    <drivers>
	        <driver name="h2" module="com.h2database.h2">
	            <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
	        </driver>
             <!-- module name must match that defined in "module.xml" -->
	        <driver name="jwOracle" module="com.oracle">
	            <xa-datasource-class>oracle.jdbc.OracleDriver</xa-datasource-class>
	        </driver>
	    </drivers>
	</datasources>
</subsystem>


What's an XA datasource?
XA datasources operates across multiple resources. Resources can be databases, JMS connections etc. For instance, if your datasource requires two databases to work together, you should configure it as XA datasource. Otherwise, it's a local data source.
  • 大小: 27.6 KB
  • 大小: 22.1 KB
  • 大小: 21.6 KB
分享到:
评论

相关推荐

    jboss7.1-Examples:具有JBOSS 7.1的EJB 2示例

    6. **安全性**:JBOSS 7.1 AS提供了基于角色的访问控制(RBAC)和JAAS(Java Authentication and Authorization Service)的集成,允许为EJB设置安全策略。 7. **部署与运行**:在JBOSS 7中,EJB不再需要ejb-jar和...

    JBoss7.1下EJB入门范例代码

    在 JBoss 7.1 中部署这些组件,你需要配置 `jboss-ejb3.xml` 或 `ejb-jar.xml` 配置文件来声明 EJB 组件,同时在 `jboss-as-client.xml` 中设置客户端连接的配置,以便正确地连接到服务器。 开发 EJB 时,你需要...

    jboss-logging-3.4.1.Final-API文档-中文版.zip

    赠送jar包:jboss-logging-3.4.1.Final.jar; 赠送原API文档:jboss-logging-3.4.1.Final-javadoc.jar; 赠送源代码:jboss-logging-3.4.1.Final-sources.jar; 赠送Maven依赖信息文件:jboss-logging-3.4.1.Final....

    jboss-threads-3.1.0.Final-API文档-中文版.zip

    赠送jar包:jboss-threads-3.1.0.Final.jar; 赠送原API文档:jboss-threads-3.1.0.Final-javadoc.jar; 赠送源代码:jboss-threads-3.1.0.Final-sources.jar; 赠送Maven依赖信息文件:jboss-threads-3.1.0.Final....

    jboss-annotations-api_1.3_spec-2.0.1.Final-API文档-中英对照版.zip

    赠送jar包:jboss-annotations-api_1.3_spec-2.0.1.Final.jar; 赠送原API文档:jboss-annotations-api_1.3_spec-2.0.1.Final-javadoc.jar; 赠送源代码:jboss-annotations-api_1.3_spec-2.0.1.Final-sources.jar;...

    jboss-logging-3.4.3.Final-API文档-中文版.zip

    赠送jar包:jboss-logging-3.4.3.Final.jar; 赠送原API文档:jboss-logging-3.4.3.Final-javadoc.jar; 赠送源代码:jboss-logging-3.4.3.Final-sources.jar; 赠送Maven依赖信息文件:jboss-logging-3.4.3.Final....

    jboss-logging-3.3.2.Final-API文档-中文版.zip

    赠送jar包:jboss-logging-3.3.2.Final.jar; 赠送原API文档:jboss-logging-3.3.2.Final-javadoc.jar; 赠送源代码:jboss-logging-3.3.2.Final-sources.jar; 赠送Maven依赖信息文件:jboss-logging-3.3.2.Final....

    jboss7.1 linux版本

    5. **配置服务器**:使用`JBOSS_HOME/bin/jboss-cli.sh`命令行工具进行服务器配置,或者直接编辑`standalone.xml`或`domain.xml`配置文件。 6. **部署应用**:将应用的WAR或EAR文件复制到`JBOSS_HOME/standalone/...

    jboss7.1wwww

    - JBoss 7.1提供了内置的安全管理框架,支持JAAS(Java Authentication and Authorization Service),可以更方便地实现用户认证和权限控制。Tomcat的安全管理需要手动配置,相对复杂。 7. **社区与商业支持**: ...

    jboss-as-sprint-int-5.0.0.GA.jar jboss-spring-int-vfs.jar

    "jboss-as-sprint-int-5.0.0.GA.jar" 和 "jboss-spring-int-vfs.jar" 是与JBoss应用服务器相关的两个关键组件,主要用于Spring框架与JBoss服务器的集成以及虚拟文件系统(Virtual File System,VFS)的支持。...

    JavaEE源代码 jboss-common

    JavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-commonJavaEE源代码 jboss-...

    jboss-as-sprint-int-5.0.0.GA.jar 和 jboss-spring-int-vfs.jar

    标题中的"jboss-as-sprint-int-5.0.0.GA.jar"和"jboss-spring-int-vfs.jar"就是这样的两个关键组件,用于帮助从Tomcat顺利过渡到JBoss环境。 首先,我们来详细了解一下`jboss-as-sprint-int-5.0.0.GA.jar`。这个...

    jboss-websocket-api_1.1_spec-2.0.0.Final-API文档-中英对照版.zip

    赠送jar包:jboss-websocket-api_1.1_spec-2.0.0.Final.jar; 赠送原API文档:jboss-websocket-api_1.1_spec-2.0.0.Final-javadoc.jar; 赠送源代码:jboss-websocket-api_1.1_spec-2.0.0.Final-sources.jar; 赠送...

    JavaEE源代码 jboss-jmx

    JavaEE源代码 jboss-jmxJavaEE源代码 jboss-jmxJavaEE源代码 jboss-jmxJavaEE源代码 jboss-jmxJavaEE源代码 jboss-jmxJavaEE源代码 jboss-jmxJavaEE源代码 jboss-jmxJavaEE源代码 jboss-jmxJavaEE源代码 jboss-...

    JavaEE源代码 jboss-cache

    JavaEE源代码 jboss-cacheJavaEE源代码 jboss-cacheJavaEE源代码 jboss-cacheJavaEE源代码 jboss-cacheJavaEE源代码 jboss-cacheJavaEE源代码 jboss-cacheJavaEE源代码 jboss-cacheJavaEE源代码 jboss-cacheJavaEE源...

    JavaEE源代码 jboss-system

    JavaEE源代码 jboss-systemJavaEE源代码 jboss-systemJavaEE源代码 jboss-systemJavaEE源代码 jboss-systemJavaEE源代码 jboss-systemJavaEE源代码 jboss-systemJavaEE源代码 jboss-systemJavaEE源代码 jboss-...

    jboss-logging-3.4.3.Final-API文档-中英对照版.zip

    赠送jar包:jboss-logging-3.4.3.Final.jar; 赠送原API文档:jboss-logging-3.4.3.Final-javadoc.jar; 赠送源代码:jboss-logging-3.4.3.Final-sources.jar; 赠送Maven依赖信息文件:jboss-logging-3.4.3.Final....

    jboss-eap-7.2.0.zip

    【JBoss EAP 7.2.0:企业级应用平台详解】 JBoss EAP(Enterprise Application Platform)是Red Hat公司推出的一款开源、基于Java EE(现在称为Jakarta EE)的应用服务器,它为企业级应用程序提供了稳定、安全和可...

    jboss-websocket-api_1.1_spec-2.0.0.Final-API文档-中文版.zip

    赠送jar包:jboss-websocket-api_1.1_spec-2.0.0.Final.jar; 赠送原API文档:jboss-websocket-api_1.1_spec-2.0.0.Final-javadoc.jar; 赠送源代码:jboss-websocket-api_1.1_spec-2.0.0.Final-sources.jar; 赠送...

Global site tag (gtag.js) - Google Analytics