MyEclipse EJB Project 快速开始 五

8. 创建一个 Session EJB – 2部分

Part-1, 创建了一个会话 EJB, 我们的示范了创建TraderBean类的过程。在这部分我们将添加业务方法同时包含XDoclet注释到TraderBean类中和用XDoclet去更新在7.2里创建的TraderTraderHome接口

当我们创建初始化的TraderBean.java 类时,EJB 创建向导添加一个业务方法例子,你可以把它作为你添加业务方法的模版。注意这个方法包含 javadoc标签 @ejb.interface-method。这个自定义的ejbdoclet 标签标识它为一个EJB接口方法的实现。当XDoclet在这个类上运行时,Trader.java EJB 接口类将被修订包含所有的带@ejb.interface-method的方法。

 

TraderBean example method

/**
  * An example business method
  *
  * @ejb.interface-method view-type = "remote"
  *
  * @throws EJBException Thrown if method fails due to system-level error.
  */
 public void replaceWithRealBusinessMethod() throws EJBException {
  // rename and start putting your business logic here< BR >  }
 *

 

  1. 开始通过向TraderBean.java 类中添加如下的两个方法并且保存你的更改。

TraderBean Business Methods

/**
  * Buys shares of a stock for a named customer.
  *
  * @param customerName      String Customer name
  * @param stockSymbol       String Stock symbol
  * @param shares            int Number of shares to buy
  * @return                  Number of shares purchased
  *
  * @ejb.interface-method
  */
 public int buy(String stockSymbol, int shares) {

   System.out.println("Buying "+shares+" shares of "+stockSymbol + ". Good move.");

   return shares;
 }

 /**
  * Sells shares of a stock for a named customer.
  *
  * @param customerName      String Customer name
  * @param stockSymbol       String Stock symbol
  * @param shares            int Number of shares to buy
  * @return                  The number for shares sold
  *
  * @ejb.interface-method
  */
 public int sell(String stockSymbol, int shares) {

   System.out.println("Selling "+shares+" shares of "+stockSymbol);

   return shares;
 }

 

 

  1. 下次在firstejb 工程上运行XDoclet重新同步Trader TraderHome 类和部署描述符(详细清查看Section 7.2)。

  2. Java 编辑器中打开 Trader.java EJB 接口并且注意添加的buy() sell() 业务方法。

 

 

Trade EJB Interface

/*
 * Generated by XDoclet - Do not edit!
 */
package com.genuitec.trader.interfaces;

/**
 * Remote interface for Trader.
 * @author XDoclet
 */
public interface Trader
   extends javax.ejb.EJBObject
{
   /**
    * Buys shares of a stock for a named customer.
    * @param customerName String Customer name
    * @param stockSymbol String Stock symbol
    * @param shares int Number of shares to buy
    * @return Number of shares purchased
    */
   public int buy( java.lang.String stockSymbol,int shares )
      throws java.rmi.RemoteException;

   /**
    * Sells shares of a stock for a named customer.
    * @param customerName String Customer name
    * @param stockSymbol String Stock symbol
    * @param shares int Number of shares to buy
    * @return The number for shares sold
    */
   public int sell( java.lang.String stockSymbol,int shares )
      throws java.rmi.RemoteException;

}

 

当你在Java编辑器中写入XDoclet功能并且Doclet注释时,注意XDoclet 代码完成功能是可用的。MyEclipse扩展了Java编辑器通过加入这个功能同时有能力在EJB API 上调用代码完成。

  1. Java编辑器中打开Trade.java Bean 找到javadoc然后把鼠标停放在"view-type" XDoclet 注释上.

敲击 ctrl+space 去调用对这个注释的代码完成支持功能。

Figure 18.  XDoclet property value code completion

  1. Place your cursor on a new line after the jndi-name tag.

  2. Enter Ctrl+Space to see XDoclet code completion suggestions for other available @ejb.bean tags not already specified.

  3. 把你的鼠标放在jndi-name标签后的新行上。

  4. 敲击 Ctrl+Space 去查看XDoclet 代码补全提示那些可用的但还没有指定的@ejb.bean 标签。

Figure 19. XDoclet property code completion

Back to Top

9. Deploying an EJB Project

企业文档文件(EAR) J2EE规范指定的唯一需要发布的文件。那么,规范制订了应用程序服务器详细的部署模式。应用程序服务器如JbossWeblogic 可支持直接的部署EJB Jar文档。直接部署EJB Jar 文件的一个约束是没有规定EJB jar文档需要的可选包。查看J2EE 1.4 规范关于可选包发布细节在Section 8.2 中。

这部分展示一个短小的说明如何发布firstejb工程作为单独的EJB Jar 文档到一个本地的Jboss3.2 实力中。请查看Application Server Quickstart 一个彻底的发布过程的向导。

 

  1. 配置一个JBoss 3.2 应用程序服务器在MyEclipse Application Server preference

    1. MyEclipse 菜单条中打开Jboss服务器配置属性;选择
      Window > Preferences > MyEclipse > Application Servers > JBoss 3.

    2. 选择 Enable单选按钮

    3. 选择 Browse... 查找 JBoss 安装路径根目录

    4. 选择 JBoss3 JDK 属性也并且选择完整的JDK,而不仅仅是JRE注意:你可能需要添加一个新的JDK 如果仅仅有JRE 被列出。

  1. 发布 firstejb 工程到JBoss 3 服务器上

    1. MyEclipse 工具条上选择发布按钮,   或者右击firstejb 工程然后选择MyEclipse >Add and Remove Project Deployments... 这将打开发布对话框。

    2. 选择firstejb Project 区域里选择 Add... 软后选择配置JBoss 3 服务器。

    3. 选择打包的或打开的发布;Jboss两种发布方式都支持。

  1. 运行 JBoss 应用服务器

    1. MyEclipse 工具条上选择应用服务器管理按钮,  然后打开菜单到JBoss3 > Start

  1. 监视在Console view 中显示的JBoss stdout and stderr 消息。

    1. 检查消息日志如图18显示的EJB 被成功部署的一条消息。

Figure 20. Console output of JBoss showing the EJB was successfully deployed

展开阅读全文

myeclipse无法创建web project

08-03

可以创建java project,但是创建web project 点next没有反应,提示An error has occurred. See error log for more details.rncom/genuitec/eclipse/core/vU 。之前一直用好着的,突然出现的问题。rnlog文件:rn!ENTRY org.eclipse.ui 4 0 2015-08-03 19:35:11.197rn!MESSAGE Unhandled event loop exceptionrn!STACK 0rnjava.lang.NoClassDefFoundError: com/genuitec/eclipse/core/vUrn at com.genuitec.eclipse.j2eedt.ui.wizard.WebProjectWizard.init(WebProjectWizard.java:52)rn at org.eclipse.ui.internal.dialogs.WorkbenchWizardNode.getWizard(WorkbenchWizardNode.java:185)rn at org.eclipse.jface.wizard.WizardSelectionPage.getNextPage(WizardSelectionPage.java:104)rn at org.eclipse.ui.internal.dialogs.WorkbenchWizardSelectionPage.getNextPage(WorkbenchWizardSelectionPage.java:100)rn at org.eclipse.jface.wizard.WizardDialog.nextPressed(WizardDialog.java:908)rn at org.eclipse.jface.wizard.WizardDialog.buttonPressed(WizardDialog.java:428)rn at org.eclipse.jface.dialogs.Dialog$2.widgetSelected(Dialog.java:624)rn at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:248)rn at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)rn at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)rn at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)rn at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)rn at org.eclipse.jface.window.Window.runEventLoop(Window.java:825)rn at org.eclipse.jface.window.Window.open(Window.java:801)rn at org.eclipse.ui.actions.NewProjectAction.run(NewProjectAction.java:117)rn at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)rn at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)rn at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)rn at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)rn at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)rn at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)rn at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4169)rn at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3758)rn at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)rn at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)rn at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)rn at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)rn at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)rn at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)rn at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)rn at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:124)rn at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)rn at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)rn at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)rn at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:353)rn at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:180)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:629)rn at org.eclipse.equinox.launcher.Main.basicRun(Main.java:584)rn at org.eclipse.equinox.launcher.Main.run(Main.java:1438)rn at org.eclipse.equinox.launcher.Main.main(Main.java:1414)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at com.genuitec.pulse.eclipse.launcher.Main.main(Main.java:110) 论坛

没有更多推荐了,返回首页