Jboss 7 第一步~

未來可能會用到,先自己練習一下吧
1:將war更新於 : /jboss-as-7.1.1.Final/standalone/deployments/
2:datasource設定 : 修改/jboss-as-7.1.1.Final/standalone/configuration/standalone.xml
  • 安裝jdbc driver
Install jdbc driver have two ways.either as a deployment or as a core module.
  • copy jar to :
jboss-7.0.0.<release>/modules/com/mysql/main
  • create module.xml file
<?xml version=”1.0″ encoding=”UTF-8″?>
<!–
  ~ JBoss, Home of Professional Open Source.
  ~ Copyright 2010, Red Hat, Inc., and individual contributors
  ~ as indicated by the @author tags. See the copyright.txt file in the
  ~ distribution for a full listing of individual contributors.
  ~
  ~ This is free software; you can redistribute it and/or modify it
  ~ under the terms of the GNU Lesser General Public License as
  ~ published by the Free Software Foundation; either version 2.1 of
  ~ the License, or (at your option) any later version.
  ~
  ~ This software is distributed in the hope that it will be useful,
  ~ but WITHOUT ANY WARRANTY; without even the implied warranty of
  ~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  ~ Lesser General Public License for more details.
  ~
  ~ You should have received a copy of the GNU Lesser General Public
  ~ License along with this software; if not, write to the Free
  ~ Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  ~ 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  –>
<module xmlns=”urn:jboss:module:1.0″ name=”com.mysql”>
  <resources>
    <resource-root path=”mysql-connector-java-5.1.19-bin.jar”/>
  </resources>
  <dependencies>
    <module name=”javax.api”/>
  </dependencies>
</module>
        <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 jndi-name=”java:jboss/env/jdbc/database” pool-name=”jdbc/erp” enabled=”true” use-java-context=”true”>
                    <connection-url>jdbc:mysql://127.0.0.1:3306/test?useUnicode=true</connection-url>
                    <driver>com.mysql</driver>
                                         <transaction-isolation>TRANSACTION_READ_COMMITTED</transaction-isolation>
                    <security>
                        <user-name>root</user-name>
                        <password>password</password>
                    </security>
                                         <pool>
                                           <min-pool-size>5</min-pool-size>
                                           <max-pool-size>10</max-pool-size>
                                           <prefill>true</prefill>
                                         </pool>
                                         <statement>
                                           <prepared-statement-cache-size>32</prepared-statement-cache-size>
                                           <share-prepared-statements/>
                                         </statement>
                </datasource>
                <drivers>
                    <driver name=”h2″ module=”com.h2database.h2″>
                        <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
                    </driver>
                    <driver name=”com.mysql” module=”com.mysql.jdbc”>
                        <xa-datasource-class>com.mysql.jdbc.jdbc2.optional.MysqlXADataSource</xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>
        </subsystem>
若有遇到:service jboss.jdbc-driver.mysql (missing)錯誤,請參考:http://davidelin.blogspot.com/2012/04/jboss-7-datasource-service-jbossjdbc.html
3:jndi jdbc 的使用方式
修改web.xml,加入:
<resource-ref]]>
<descriptionjndi ]]>Datasourceerp</description]]>
<res-ref-name]]>jdbc/database</res-ref-name]]>
<res-type]]>javax.sql.DataSource</res-type]]>
<res-auth]]>Container</res-auth]]>
</resource-ref]]>
新增:WEB-INFjboss-web.xml
內容如下:
<?xmlversion=“1.0”encoding=“UTF-8”?>
<!DOCTYPEjboss-webPUBLIC“-//JBoss//DTD Web Application 2.3V2//EN” 
<jboss-web]]>
<resource-ref]]>
<res-ref-name]]>jdbc/database </res-ref-name]]>
<jndi-name]]>java:jboss/env/jdbc/database</jndi-name]]>
</resource-ref]]>   
</jboss-web]]>
其中二個檔案的res-ref-name要相同,jndi-name是在步驟2中所定義的,接下來你的系統在使用時就可以用:java:comp/env/jdbc/database,
不然你只能用java:jboss/evn/jdbc/databse,後果是你系統在移值tomcat,或從tomcat移值jboss時,就得需要調整程式的設定。
4:增加admin的方法:
# – Linux
#  bin/add-user.sh
# – Windows
#  binadd-user.bat
5:若要調整jboss的啟動參數,請修改
bin/standalone.conf
6:進入jboss-admin的方法
# – Linux
#  bin/jboss-cli.sh
# – Windows
#  binjboss-cli.bat

Related Posts