在eclipse中使用JBossIDE和xDoclet创建EJB

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

1. create EJB module(lomboz)
2. create EJB (JBoss): package must end with: .ejb
3. Config xDoclet(eclipse project properties)
  1. add standard-->standard EJB-->ejb doclet
  2. right click ejbdoclet and select jboss
    set version: 4.0
    set datasource: java:/tutorial
    set datasourcemapping: Oracle9i( look up D:\j2ee\jboss-4.0.1\server\default\conf\standardjbosscmp-jdbc.xml for it)
    set destDir: simpleejb/META-INF/ (where the the jboss.xml and jbosscmp-jdbc.xml will create)
  3. select home, interface,remoteinterface,localhome and select destdir
  4. entitypk: set destdir to simpleejb/src 
  5. set fileset
   
  3. click ok
 
4. create datasource mapping
  1. copy jdbc driver to: D:\j2ee\jboss-4.0.1\server\default\lib
  2. create table
  3. find D:\j2ee\jboss-4.0.1\docs\examples\jca\oracle-ds.xml and copy it to D:\j2ee\jboss-4.0.1\server\default\deploy
  4. update it like below:
   <datasources>
   <local-tx-datasource>
     <jndi-name>HeliumDS</jndi-name>
     <connection-url>jdbc:oracle:thin:@192.168.0.109:1521:labdb</connection-url>
     <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
     <user-name>helium</user-name>
     <password>helium</password>
     <!-- Uses the pingDatabase method to check a connection is still valid before handing it out from the pool -->
     <!--valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name-->
     <!-- Checks the Oracle error codes and messages for fatal errors -->
     <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
 
       <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->
       <metadata>
          <type-mapping>Oracle9i</type-mapping>
       </metadata>
   </local-tx-datasource>
 
 </datasources>
5. edit source code
  1. find /**
        *@ejb.bean...
  replace it with:
/**
 * @ejb.bean name="SimpleEntity"
 *           display-name="Name for SimpleEntity"
 *           description="Description for SimpleEntity"
 *           jndi-name="ejb/SimpleEntityHome"
 *           type="CMP"
 *           cmp-version="2.x"
 *           view-type="both"
 *        local-jndi-name = "ejb/SimpleEntityLocalHome"
 *           primkey-field = "domainid"
 *  @ejb.persistence table-name = "domain"
 *  @jboss.persistence table-name = "domain"
 *  @ejb:util
 *       generate="physical"      
 *
 */

 2. for each field, add code like:
 
 /**       
  *  @ejb.interface-method view-type = "both"        
  *  @ejb.persistence column-name = "domainid"        
  *  @ejb.pk-field        
  *  @return        
  */
  public abstract String getDomainId();       
 
 /**     
  *     @ejb.interface-method view-type = "both"        
  *           @param name
  *
  */        
    public abstract void setDomainId(String id);       
 
     /**         
     * @ejb.interface-method view-type = "both"        
     *  @ejb.persistence column-name = "name"        
     *  @return        
     */       
    public abstract String getName();   
   
    /**          @ejb.interface-method view-type = "both"
     *          @param name        
     */       
   
    public abstract void setName(String name); 
   
3. right click project bar and select run xDoclet. Two files are generated: jboss.xml and jbosscmp-jdbc.xml
4. setup packaging configuration: addstandard-->select EJB-->select destDir
5. run packaging
6. copy classes12.jar to D:\j2ee\jboss-4.0.1\server\default\lib
6. JBoss launcher
   1. go into debug...
   2. select jboss4.0.X
   3. put project into source
   4. run the server
7. deploy the project

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