how to generate deployment descriptor using ejbGen

2019-07-23 13:26发布

问题:

I was reading the tutorial on this page:
http://edocs.bea.com/docs/cd/E13222_01/wls/docs81/medrec_tutorials/ejbgen.html#858279

And I have the following file BankAccountEJB.java

import javax.ejb.CreateException; import javax.ejb.EntityBean; import javax.ejb.EntityContext;

public abstract class BankAccountEJB implements EntityBean {

private EntityContext context;

public void setEntityContext(EntityContext aContext) {
    context = aContext;
}

public void ejbActivate() {

}

public void ejbPassivate() {

}

public void ejbRemove() {

}

public void unsetEntityContext() {
    context = null;
}

public void ejbLoad() {

}

public void ejbStore() {

}

public abstract String getName();

public abstract void setName(String name);

public abstract Float getBalance();

public abstract void setBalance(Float balance);

public java.lang.Long ejbCreate(String name, Float balance)  throws CreateException {
    if (name == null) {
        throw new CreateException("The field \"key\" must not be null");
    }

    // TODO add additional validation code, throw CreateException if data is not valid
    setName(name);

setBalance(balance);

    return null;
}

public void ejbPostCreate(java.lang.Long key) {
    // TODO populate relationships here if appropriate
}

}

and I run java weblogic.tools.ejbgen.EJBGen -ddOnlyGen BankAccountEJB.java which produces the following error:

Exception in thread "main" com.bea.wls.ejbgen.EJBGenException: ejbName is a required attribute at com.bea.wls.ejbgen.Bean.createBeanSpecificTags(Bean.java:202) at com.bea.wls.ejbgen.Bean.(Bean.java:127) at com.bea.wls.ejbgen.EntityBean.(EntityBean.java:76) at com.bea.wls.ejbgen.EJBFactory.createBean(EJBFactory.java:135) at com.bea.wls.ejbgen.EJBFactory.createBean(EJBFactory.java:99) at com.bea.wls.ejbgen.EJBGenSGen.initModule(EJBGenSGen.java:106) at com.bea.sgen.SGen.run(SGen.java:205) at com.bea.wls.ejbgen.EJBGen.main(EJBGen.java:212) at com.bea.wls.ejbgen.EJBGen.main(EJBGen.java:238) at weblogic.tools.ejbgen.EJBGen.main(EJBGen.java:21)

Any input will be greatly appreciated~!

回答1:

Note: Are you still running Weblogic 8.1 - it's already reached end of life. Also ejbgen works with EJB 2.x and over the last 2 years, development has moved on to EJB 3, so i'd advise you to catch up on those.

Now to your specific problem.

Your code does not seem to have the required annotations for ejbgen to work.

Annotations like this which are used in generation of the descriptors.

 * @ejbgen:entity
 *   ejb-name = containerManaged
 *   table-name = ejbAccounts
 *   data-source-name = examples-dataSource-demoPool
 *   prim-key-class =  AccountPK
 *   invalidation-target = ServiceDesignEJB

As your URL says the code in the tutorial has the right data as a sample - make sure you replicate those correctly in your own code.

EJBGen uses annotations in the bean file to generate the deployment descriptor files and the EJB Java source files. EJB files in the MedRec application are already annotated for EJBGen.

For another version of ejbgen, see http://www.beust.com/ejbgen/