Jboss4.x下第一个EJB2.x程序
2008-01-05 20:34:44 来源:WEB开发网核心提示:EJB的名声很不好,尤其在SPRing框架出现以后,Jboss4.x下第一个EJB2.x程序,而EJB3似乎脱胎换骨了,而我现在学习的仍然是EJB2,启动Jboss服务器,在浏览器地址栏输入:http://localhost:8080/HelloEJB/ClientServlet然后看到浏览器输出“Hello from
EJB的名声很不好,尤其在SPRing框架出现以后,而EJB3似乎脱胎换骨了。而我现在学习的仍然是EJB2,原因是EJB3的书很难找。暑假时大概把《精通EJB》和《EJB》这两本书看过一下,现在想复习,加深理解,就从第一个HelloWorld开始。
文件结构:
E:.
│ build.xml
│
└─src
├─META-INF
│ application.xml
│ ejb-jar.xml
│ jboss.xml
│
├─powerwind
│ ClientServlet.java
│ Hello.java
│ HelloBean.java
│ HelloHome.java
│
└─WEB-INF
jboss-web.xml
web.xml
ant文件
build.xml
<?xml version="1.0"?>
<project name="Hello" default="prepare" basedir=".">
<property environment="env" />
<property name="src.dir" value="${basedir}/src" />
<property name="jboss.home" value="${env.JBOSS_HOME}" />
<property name="build.dir" value="${basedir}/build" />
<property name="classes.dir" value="${build.dir}/classes" />
<property name="dist.dir" value="${basedir}/dist" />
<path id="compile.classpath">
<pathelement location="${classes.dir}" />
<fileset dir="${jboss.home}/client">
<include name="jboss-j2ee.jar" />
<include name="javax.servlet.jar" />
<include name="commons-httpclient.jar" />
</fileset>
</path>
<target name="prepare">
<mkdir dir="${classes.dir}" />
<mkdir dir="${dist.dir}" />
<copy todir="${build.dir}">
<fileset dir="${src.dir}">
<include name="WEB-INF/*.xml" />
<include name="META-INF/*.xml" />
</fileset>
</copy>
</target>
<target name="clean">
<delete dir="${build.dir}" />
<delete dir="${dist.dir}" />
</target>
<target name="compile" depends="prepare">
<javac srcdir="${src.dir}" destdir="${classes.dir}">
<classpath refid="compile.classpath" />
</javac>
</target>
<target name="jar" depends="compile">
<jar destfile="${dist.dir}/HelloEJB.jar">
<fileset dir="${build.dir}">
<exclude name="META-INF/application.xml" />
<include name="META-INF/*.xml" />
</fileset>
<fileset dir="${classes.dir}">
<include name="**/*.class" />
</fileset>
</jar>
</target>
<target name="war" depends="jar">
<jar destfile="${dist.dir}/HelloEJB.war">
<fileset dir="${build.dir}">
<include name="WEB-INF/*.xml" />
</fileset>
</jar>
</target>
<target name="ear" depends="war">
<jar destfile="${dist.dir}/HelloEJB.ear">
<fileset dir="${dist.dir}">
<include name="HelloEJB.jar" />
<include name="HelloEJB.war" />
</fileset>
<fileset dir="${build.dir}">
<include name="META-INF/application.xml" />
</fileset>
</jar>
</target>
<target name="deploy" depends="ear">
<copy file="${dist.dir}/HelloEJB.ear" overwrite="true"
todir="${jboss.home}/server/default/deploy" />
</target>
</project>
</enterprise-beans> </jboss> application.xml <?xml version="1.0"?> <application> <display-name>HelloEJB J2EE Application</display-name> <module> <web> <web-uri>HelloEJB.war</web-uri> <context-root>/HelloEJB</context-root> </web> </module> <module> <ejb>HelloEJB.jar</ejb> </module> </application> jboss-web.xml <?xml version="1.0"?> <jboss-web> <ejb-ref> <ejb-ref-name>HelloEJB</ejb-ref-name> <jndi-name>HelloEJB</jndi-name> </ejb-ref> </jboss-web> web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet>
<servlet-name>ClientServlet</servlet-name> <servlet-class>powerwind.ClientServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>ClientServlet</servlet-name> <url-pattern>/ClientServlet</url-pattern> </servlet-mapping> <ejb-ref> <ejb-ref-name>HelloEJB</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>powerwind.HelloHome</home> <remote>powerwind.Hello</remote> </ejb-ref> </web-app> 输入 ant –deploy 部署,启动Jboss服务器,在浏览器地址栏输入: http://localhost:8080/HelloEJB/ClientServlet 然后看到浏览器输出“Hello from ejb”,就是成功了。
更多的请看:http://www.QQread.com/windows/2003/index.Html
更多的请看:http://www.qqread.com/windows/2003/index.html
</enterprise-beans> </jboss> application.xml <?xml version="1.0"?> <application> <display-name>HelloEJB J2EE Application</display-name> <module> <web> <web-uri>HelloEJB.war</web-uri> <context-root>/HelloEJB</context-root> </web> </module> <module> <ejb>HelloEJB.jar</ejb> </module> </application> jboss-web.xml <?xml version="1.0"?> <jboss-web> <ejb-ref> <ejb-ref-name>HelloEJB</ejb-ref-name> <jndi-name>HelloEJB</jndi-name> </ejb-ref> </jboss-web> web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet>
<servlet-name>ClientServlet</servlet-name> <servlet-class>powerwind.ClientServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>ClientServlet</servlet-name> <url-pattern>/ClientServlet</url-pattern> </servlet-mapping> <ejb-ref> <ejb-ref-name>HelloEJB</ejb-ref-name> <ejb-ref-type>Session</ejb-ref-type> <home>powerwind.HelloHome</home> <remote>powerwind.Hello</remote> </ejb-ref> </web-app> 输入 ant –deploy 部署,启动Jboss服务器,在浏览器地址栏输入: http://localhost:8080/HelloEJB/ClientServlet 然后看到浏览器输出“Hello from ejb”,就是成功了。
[]
更多精彩
赞助商链接