I learned how to call EJB in JBoss.
Then I learned how to call JBoss's EJB FOR THE WEB Project in Tomcat.
Environment:
Tomcat5.5 + jboss4.0.4
First, create a Java project in eclipse.
Create two files
Helloworld. Java
Package com;
Public interface helloworld {
Public String sayhello (string name );
}
Helloworldbean. Java
Package com;
IMPORT javax. EJB. Remote;
IMPORT javax. EJB. stateless;
@ Stateless
@ Remote ({helloworld. Class })
Public class helloworldbean implements helloworld {
Public String sayhello (string name ){
// Todo auto-generated method stub
Return name + "is the first remote EJB ";
}
}
Put the jboss-ejb3x.jar under JBoss in the classpath of the project.
Then package it into helloworld. Jar
Deploy to the C: \ jboss-4.0.4.GA \ Server \ All \ deploy directory.
The JBoss console is displayed.
Create a web project.
Testhello
Create an index. jsp
<% @ Page Language = "Java" contenttype = "text/html; charset = ISO-8859-1"
Pageencoding = "ISO-8859-1" %>
<HTML>
<Head>
<Title> the first EJB </title>
</Head>
<Body>
<%
Java. util. properties props = new java. util. properties ();
Props. setproperty ("Java. Naming. Factory. Initial", "org. jnp. Interfaces. namingcontextfactory ");
Props. setproperty ("Java. Naming. provider. url", "localhost: 1099 ");
Props. setproperty ("Java. Naming. Factory. url. pkgs", "org. JBoss. Naming ");
Javax. Naming. initialcontext CTX;
Try {
CTX = new javax. Naming. initialcontext (props );
Com. helloworld = (COM. helloworld) CTX. Lookup ("helloworldbean/remote ");
Out. println (helloworld. sayhello ("Michael "));
} Catch (javax. Naming. namingexception e ){
E. printstacktrace ();
}
%>
</Body>
</Html>
Put these 6 jar: jboss-aop-jdk50.jar, jboss-aspect-library-jdk50.jar, jboss-ejb3.jar, jboss-remoting.jar. Put in the classpath of the project.
Then package it into testhello. War.
Deploy to Tomcat
Then run the command to obtain the result on the interface.
Michael is the first remote EJB