<Ejb3InAction> Sample01 for Glassfish - HelloUser EJB

0. Prerequisite


1) Download Weblogic based sample code from following URL, and extract to your directory.

    https://www.manning.com/books/ejb3-in-action

My directory is $HOME/student/ejbactGF


2) Add environment variables in your environment:

    export JAVA_HOME=/opt/jdk

    export AS_INSTALL_PARENT=~/glassfish4

    export AS_INSTALL=$AS_INSTALL_PARENT/glassfish

    export PATH=$JAVA_HOME/bin:$AS_INSTALL_PARENT/bin:$AS_INSTALL/bin:$PATH


3) Start glassfish domain and derby

    $ asadmin start-domain

    Waiting for domain1 to start ............

    Successfully started the domain : domain1

    domain Location: /home/weblogic/glassfish4/glassfish/domains/domain1

    LogFile: /home/weblogic/glassfish4/glassfish/domains/domain1/logs/server.log

    AdminPort: 4848

    Command start-domain executed successfully.


    $ asadmin start-database

    Starting database in Network Server mode on host 0.0.0.0 and port 1527.

    

    Starting database in the background.

    Log redirected to /home/weblogic/student/ejbactGF/derby.log.

    Commands tart-database executed successfully.


4) Create db instance if need

#!/bin/sh

java \
	-cp "$JAVA_HOME/db/lib/derby.jar:$JAVA_HOME/db/lib/derbynet.jar:$JAVA_HOME/db/lib/derbytools.jar:$JAVA_HOME/db/lib/derbyoptionaltools.jar:$JAVA_HOME/db/lib/derbyclient.jar" \
	-Dij.driver=org.apache.derby.jdbc.ClientDriver \
	-Dij.protocol=jdbc:derby: -D"ij.database=//localhost:1527/sun-appserv-samples;create=true" \
	-Dij.user=app -Dij.password=app \
	org.apache.derby.tools.ij

To make things easy, here I use the default database sun-appserv-samples, which related to following JDBC resources in glassfish:

    Connectionpool – DerbyPool

    Resource– jdbc/__default



1. Customize general configuration


    $ cd $HOME/student/ejbactGF

    $ vi common.xml # customize general configure for all chapters

    $ diff -u common.xml.orig common.xml

...

    <!--** Customize as per your environment **** -->

    - <property name="J2EE_HOME" value="${env.J2EE_HOME}"/>

    + <property name="J2EE_HOME" value="${env.AS_INSTALL}"/>

    <propertyname="JAVA_HOME" value="${env.JAVA_HOME}"/>

    - <property name="ASADMIN" value="asadmin.bat"/>

    - <property name="WSIMPORT" value="wsimport.bat"/>

    - <property name="APPCLIENT" value="appclient.bat"/>

    + <property name="ASADMIN" value="asadmin"/>

    + <property name="WSIMPORT" value="wsimport"/>

    + <property name="APPCLIENT" value="appclient"/>

    + <property name="derby.driver" value="org.apache.derby.jdbc.ClientDriver" />

    + <property name="derby.url" value="jdbc:derby://localhost:1527/sun-appserv-samples;create=true;ServerName=localhost;databaseName=sun-appserv-samples"/>

    + <property name="derby.username" value="app"/>

    + <property name="derby.password" value="app"/>

...

    + <target name="db-setup" depends="init"description="Database setup for Derby">

    +     <sql driver="${derby.driver}"

    +         url="${derby.url}"

    +         userid="${derby.username}"password="${derby.password}"

    +         οnerrοr="continue"

    +         print="yes"

    +         src="sql/tables.sql"

    +         classpath="${JAVA_HOME}/db/lib/derbyclient.jar"/>

    + </target>

    +

    + <target name="drop-que">

    +      <exec executable="${J2EE_HOME}/bin/${ASADMIN}"failοnerrοr="true" vmlauncher="false">

    +            <arg line=" --host ${admin.host}" />

    +            <arg line=" --port ${admin.port}" />

    +            <arg line=" delete-jms-resource" />

    +            <arg line="${jms.queue}" />

    +       </exec>

    + </target>

    +

    + <target name="crt-que">

    +       <exec executable="${J2EE_HOME}/bin/${ASADMIN}"failοnerrοr="true" vmlauncher="false">

    +            <arg line=" --host ${admin.host}" />

    +            <arg line=" --port ${admin.port}" />

    +            <arg line=" create-jms-resource" />

    +            <arg line=" --restype javax.jms.Queue" />

    +            <arg line="${jms.queue}" />

    +       </exec>

    + </target>



2. Customize chapter1


    $ cd $HOME/student/ejbactGF/chapter1

    $ for i in `find * -name "*.orig"`; do j=`expr $i :'\(.*\).orig'`; echo diff -u $i $j; diff -u $i $j; echo; echo; done

    diff-u build.xml.orig build.xml

...

    level="verbose"></echo>

    - <echo message="asadmin.bat undeploy --user ${admin.user}--password ${admin.password} --host ${admin.host} --port${admin.port} chapter1"></echo>

    + <echo message="asadmin undeploy --user ${admin.user}--password ${admin.password} --host ${admin.host} --port${admin.port} chapter1"></echo>

    <exec executable="${J2EE_HOME}/bin/${ASADMIN}" failοnerrοr="false">

...

    - <echo message="asadmin.bat deploy --user ${admin.user}--password ${admin.password} --host ${admin.host} --port${admin.port} --upload=true lib/chapter1.ear"></echo>

    + <echo message="asadmin deploy --user ${admin.user}--password ${admin.password} --host ${admin.host} --port${admin.port} --upload=true lib/chapter1.ear"></echo>

    <exec executable="${J2EE_HOME}/bin/${ASADMIN}" failοnerrοr="false">



3. Build, deploy and run


    $ cd $HOME/student/ejbactGF/chapter1

    $ ant clean build

    $ ant deploy

    $ ant run

...

    run:

    [echo] Executing client class using/home/weblogic/glassfish4/glassfish/bin/appclient

    [exec] Invoked EJB successfully .. see server console for output


From server log we can see:

Hello Curious George welcome to EJB 3 In Action!


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值