EJBGen Ant 构建成功返回警告未找到 EJB 文件

EJBGen Ant Build Successfull Returning Warning no EJB File Found

我正在使用 apache ant 执行构建来构建持续集成。

目前我们遇到了一些奇怪的问题ant warning。我已经将生成 EJBGen 的 ant 任务指向名为 DnAOperationEJB.java

的 EJB 文件

附上ant构建文件:

<ejbgen source="1.6" outputDir="${staging.dir}" descriptorDir="ejbModule\META-INF" forceGeneration="true"
            ejbSuffix = "."
            localSuffix = "Local"
            localHomeSuffix = "LocalHome">
            <fileset dir="ejbModule/sample/oss/dna/ejb">
                    <contains text="@Session"/>
                    <contains text="@LocalMethod"/>
            </fileset>
</ejbgen>

编译后,构建结果SUCCESSFUL如下图

   [ejbgen] Invoking EJBGen with the following command line:
   [ejbgen]   -d
   [ejbgen]   C:\Users\Jenkins Project\Sample\DnA_Ejb\staging
   [ejbgen]   -forceGeneration
   [ejbgen]   -source
   [ejbgen]   1.6
   [ejbgen]   -ejbSuffix
   [ejbgen]   .
   [ejbgen]   -localSuffix
   [ejbgen]   Local
   [ejbgen]   -localHomeSuffix
   [ejbgen]   LocalHome
   [ejbgen]   -descriptorDir
   [ejbgen]   C:\Users\Jenkins Project\Sample\DnA_Ejb\ejbModule\META-INF
   [ejbgen]   C:\Users\Jenkins Project\Sample\DnA_Ejb\ejbModule\sample\oss\dna\ejb\DnAOperationEJB.java
   [ejbgen] EJBGen WebLogic Server 10.3.6.0  Tue Nov 15 08:52:36 PST 2011 1441050
   [ejbgen]  Warning:  No EJBGen file found!

BUILD SUCCESSFUL
Total time: 1 second

但是从 EJB Gen 生成的文件没有显示在目标文件夹中。我认为这是由于 Ant 找不到 EJBGen 文件,如 Warning: No EJBGen file found!

所示

DnAOperationEJB.java源码如下:

/*
 * GenericSessionBean subclass automatically generated by OEPE.
 *
 * Please complete the ejbCreate method as needed to properly initialize new instances of your bean and add
 * all required business methods. Also, review the Session, JndiName and FileGeneration annotations 
 * to ensure the settings match the bean's intended use.
 */
@Session(ejbName = "DnAOperationEJB", initialBeansInFreePool = "5", maxBeansInFreePool = "20", transactionType = SessionTransactionType.CONTAINER, defaultTransaction = TransactionAttribute.SUPPORTS)
@JndiName(local = "ejb.DnAOperationEJBLocalHome")
@FileGeneration(remoteClass = Constants.Bool.FALSE, remoteHome = Constants.Bool.FALSE, localClass = Constants.Bool.TRUE, localHome = Constants.Bool.TRUE)
public class DnAOperationEJB extends GenericSessionBean implements SessionBean {

    private static final long serialVersionUID = 1L;
    private static String className = DnAOperationEJB.class.getName();
    /*
     * (non-Javadoc)
     * 
     * @see weblogic.ejb.GenericSessionBean#ejbCreate()
     */
    public void ejbCreate() 
    {
        // IMPORTANT: Add your code here
    }


//  @LocalMethod()
    @LocalMethod(transactionAttribute =  TransactionAttribute.NOT_SUPPORTED)
    public Context createContext(String xmlIn, String tID)
    {
        Log.debug("Executing createContext", className, tID);

        try
        {
            Context ctx = new Context();
            ctx.setTransactionID(tID);
            ctx.setRequest(xmlIn);

            return ctx;
        }
        catch (Exception e) 
        {
            throw new RuntimeException(e);
        }
        finally
        {
            Log.debug("createContext executed", className, tID);
        }       
    }

//  @LocalMethod()
    @LocalMethod(transactionAttribute =  TransactionAttribute.REQUIRES_NEW)
    public void executeOperation(Context ctx) throws Exception 
    {
        Log.debug("Executing executeOperation", className, ctx.getTransactionID());
        Operation operation = null;
        try
        {
            operation = OSSFactory.newOperation(ctx);
            Log.debug("OperationBegin: " + ctx.getRequest().toString(), className, ctx.getTransactionID());
            operation.execute();
        }
        catch(Exception e)
        {
            Log.exception(e, className, ctx.getTransactionID());
            e.printStackTrace();
            getSessionContext().setRollbackOnly();
            Log.debug("Transaction rolled back",  className, ctx.getTransactionID());
            throw e;
        }
        finally
        {
            if(operation != null)
                operation.terminate(false);
            Log.debug("executeOperation executed", className, ctx.getTransactionID());
        }
    }

    @LocalMethod(transactionAttribute =  TransactionAttribute.NOT_SUPPORTED)
    public String generateResponse(Context ctx)  throws Exception 
    {
        Log.debug("Executing generateResponse", className, ctx.getTransactionID());

        Operation operation = null;             
        try
        {
            operation = OSSFactory.newOperation(ctx);
            return operation.generateResponse(null);
        }
        finally
        {
            if(operation != null)
                operation.terminate(false);
            Log.debug("generateResponse executed", className, ctx.getTransactionID());
        }
    }

    @LocalMethod(transactionAttribute =  TransactionAttribute.NOT_SUPPORTED)
    public String generateErrorResponse(Context ctx, Exception exception) 
    {
        Log.debug("Executing generateErrorResponse", className, ctx.getTransactionID());

        Operation operation = null;             

        try
        {
            operation = OSSFactory.newOperation(ctx);
            return operation.generateResponse(exception);
        }
        catch(Exception e)
        {
            Log.exception(e, className, ctx.getTransactionID());
            e.printStackTrace();
            throw new RuntimeException(e);
        }
        finally
        {
            if(operation != null)
                operation.terminate(false);
            Log.debug("generateErrorResponse executed", className, ctx.getTransactionID());
        }
    }

//  @LocalMethod()
    @LocalMethod(transactionAttribute =  TransactionAttribute.REQUIRES_NEW)
    public void terminate (Context ctx)
    {
        Log.debug("Executing terminate", className, ctx.getTransactionID());

        Operation operation = null;
        try
        {
            operation = OSSFactory.newOperation(ctx);
            operation.terminate(true);
        }
        catch(Exception e)
        {
            Log.exception(e, className, ctx.getTransactionID());
            e.printStackTrace();
        }
    }
}

但是我已经把EJB文件放到ant任务中了。

任何想法,帮助 and/or 评论?

找到最佳解决方案后,出现了针对此类错误的解决方案。

首先:详细 你的 EJBGEN 函数。

<ejbgen source="1.6" outputDir="${staging.dir}" descriptorDir="ejbModule\META-INF" forceGeneration="true" 
verbose="true"
            ejbSuffix = "."
            localSuffix = "Local"
            localHomeSuffix = "LocalHome">
            <fileset dir="ejbModule/sample/oss/dna/ejb">
                    <contains text="@Session"/>
                    <contains text="@LocalMethod"/>
            </fileset>
</ejbgen>

然后 second,将源从 1.6 更改为 1.5

在我的例子中,如果我将 1.6 放入源中,则会抛出另一个错误。 Exception in thread "main" com.bea.wls.ejbgen.EJBGenException: ejbName is a required attribute

在此处回答此错误 how to generate deployment descriptor using ejbGen for weblogic?

然后third,把-lib参数放在你的ant任务中。如果您不指定不在类路径中的库,则这是可选参数。 示例:

ant build -lib ../lib -v > build.log