`

基于NetBeans的Java EE客户端应用程序(一)

 
阅读更多
<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>

文档当前处于草稿状态

本教程将展示如何在 NetBeans 平台上方便地创建应用程序客户端。将以 Database Reader 为例进行演示说明。

目录

l 要求

l 安装和配置

l 项目创建

l 企业应用程序开发

l 修改构建脚本

l 数据库生成实体类

l 创建带有远程接口的无状态的会话 Bean以便与持久单元进行通信

l 修改 dbreader-ear-app-client 应用程序客户端模块

l NetBeans 模块开发

l 设置 dbreader NetBeans 模块套件

l 设置 customers NetBeans 模块

l 创建 Window 组件

l 编写 Customers 顶部组件逻辑

l 运行应用程序


l Java(TM) SE Development Kit 5.0

l NetBeans IDE 5.5.1<shape id="_x0000_i1029" style="WIDTH: 6pt; HEIGHT: 6pt" alt="" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/images/out.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image001.png"></imagedata></shape>

l NetBeans Platform <chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">5.5.1</chsdate>

l GlassFish v2 build 33

安装和配置

安装全部所需产品(在产品站点上可以获取安装指南)。在开始安装之前,必须进行一些设置。首先启动 NetBeans IDE <chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">5.5.1</chsdate>并注册 GlassFish v2。在 Runtime 选项卡中右键单击 Servers 节点,然后选择 Add server(选中 Sun Java Application Server)。

<shape id="_x0000_i1031" style="WIDTH: 409.5pt; HEIGHT: 237.75pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/addserver.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/addserver.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image003.png"></imagedata></shape>

现在将 NetBeans Platform 注册到 IDE 中。实际上此步骤与添加新服务器的操作是相同。选择 Tools -> NetBeans Platform Manager,单击 Add Platform 按钮,然后按照向导进行操作(选择下载的 NetBeans Platform <chsdate w:st="on" isrocdate="False" islunardate="False" day="30" month="12" year="1899">5.5.1</chsdate>作为新平台)。

<shape id="_x0000_i1032" style="WIDTH: 462.75pt; HEIGHT: 306pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/addplatform.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/addplatform.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image005.png"></imagedata></shape>

项目创建

该创建全部项目了。我们需要 NetBeans Module Suite 项目、(添加到 NetBeans Module Suite 中的)NetBeans Module 项目以及包含 Application Client EJB 模块的 Enterprise Application 项目。首先创建 NetBeans Module Suite 项目。将其命名为 dbreader。至于所使用的平台,我们选择前面已注册的新平台。

<shape id="_x0000_i1033" style="WIDTH: 447.75pt; HEIGHT: 288.75pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createsuite1.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createsuite1.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image007.png"></imagedata></shape>

<shape id="_x0000_i1034" style="WIDTH: 483.75pt; HEIGHT: 312pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createsuite2.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createsuite2.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image009.png"></imagedata></shape>

然后创建 NetBeans Module 项目。将其命名为 customers。并选择Add to Module Suite 将它添加到 dbreader 套件。所有其他选项都保持默认值。

<shape id="_x0000_i1035" style="WIDTH: 461.25pt; HEIGHT: 290.25pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createmodule.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createmodule.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image011.png"></imagedata></shape>

实际上我们已经创建了 NetBeans Module 项目,现在必须创建 Java EE 部分。因此,我们将创建带有 Application Client EJB 模块的 Enterprise Application 项目。将其命名为 dbreader-ear。它包含 Application Client EJB 模块。不包含. Exclude Web 模块。还要选择 Java EE 5 版本,并选中 Sun Java Application Server 作为开发服务器。

<shape id="_x0000_i1036" style="WIDTH: 450.75pt; HEIGHT: 294pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createear1.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createear1.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image013.png"></imagedata></shape>

<shape id="_x0000_i1037" style="WIDTH: 423.75pt; HEIGHT: 276pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createear2.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/createear2.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image015.png"></imagedata></shape>

非常好!您已经成功创建了所需的所有项目。现在 Projects 选项卡中应包含以下内容。

<shape id="_x0000_i1038" style="WIDTH: 190.5pt; HEIGHT: 97.5pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/projects.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/projects.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image017.png"></imagedata></shape>

企业应用程序开发

修改构建脚本

因为必须将 dbreader 套件 jnlp distro 打包到 dbreader ear 中,所以我们需要修改 dbreader-ear build.xml 脚本。应将以下代码添加到 dbreader-ear build.xml 中。

 <property name="dbreader.home" value="../"></property>
 
<target name="build-dbreader-jnlp"></target>
 <java classname="org.apache.tools.ant.Main" dir="${dbreader.home}" failonerror="true" fork="true"></java>
 <jvmarg value="-Dant.home=${ant.home}"></jvmarg>
 <arg value="build-jnlp"></arg>
 <classpath path="${java.class.path}"></classpath>
 
 
 
<target name="pre-dist" depends="build-dbreader-jnlp"></target>
 <!-- dbreader.home must point to DatabaseReader Application home directory -->

 <mkdir dir="${build.dir}/lib"></mkdir>
 <copy todir="${build.dir}/lib"></copy>
 <fileset dir="${dbreader.home}/build/jnlp/app" includes="*.jar"></fileset>
 <fileset dir="${dbreader.home}/build/jnlp/branding" includes="*.jar"></fileset>
 <fileset dir="${dbreader.home}/build/jnlp/netbeans" includes="*.jar"></fileset>
 
 

可以在 Files 视图中访问 build.xml 文件。

<shape id="_x0000_i1040" style="WIDTH: 496.5pt; HEIGHT: 219pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/editearbuild2.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/editearbuild2.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image021.png"></imagedata></shape>

从数据库生成实体类

我们已经准备好了 dbreader-ear 项目基础架构。现在必须从 sample 数据库生成实体类。在 Project 选项卡中右键单击 dbreader-ear-ejb 项目,然后选择 New -> Entity Classes From Database。在向导窗口中,选择 jdbc/sample 数据源作为data source,并选中 CUSTOMER 表。

<shape id="_x0000_i1041" style="WIDTH: 420pt; HEIGHT: 273.75pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/generateentity1.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/generateentity1.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image023.png"></imagedata></shape>

在下一个向导面板中,键入实体类的包。键入db。然后单击 create persistence unit。将出现 Persistence unit 对话框。单击 Create。然后单击 Finish 按钮来完成向导。

<shape id="_x0000_i1042" style="WIDTH: 6in; HEIGHT: 270.75pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/generateentity2.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/generateentity2.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image025.png"></imagedata></shape>

现在我们已经为 jdbc/sample 数据库生成实体类。在 dbreader-ear-ejb 项目下可以看到所生成的类。

<shape id="_x0000_i1043" style="WIDTH: 220.5pt; HEIGHT: 311.25pt" alt="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/generateentity3.png" type="#_x0000_t75"><imagedata o:href="http://wiki.netbeans.org/wiki/attach/DevFaqAppClientOnNbPlatformTut/generateentity3.png" src="file:///C:/DOCUME~1/fujiang/LOCALS~1/Temp/msohtml1/01/clip_image027.png"></imagedata></shape>

要求




分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics