EJB 3.0 Simplified:
Make Directory :
C:\simple-ejb3> & C:\simple-ejb3\classes> & C:\simple-ejb3\src\foo>
C:\simple-ejb3> tree /A /F
+---classes
| \---foo
\---src
\---foo
Client.java
FooBean.java
FooRemote.java
---------------
FooRemote.java:
---------------
package foo;
import javax.ejb.*;
@Remote
public interface FooRemote {
public String echo(String s);
}
-------------
FooBean.java:
-------------
package foo;
import javax.ejb.*;
@Stateless
public class FooBean implements FooRemote {
public String echo(String s) {
return s;
}
}
-----------
Client.java
-----------
package foo;
import javax.ejb.*;
import javax.naming.*;
public class Client {
public static void main(String[] args) throws Exception {
//JBoss' default remote jndi: <ejb-name>/remote
final String jndiName = "FooBean/remote";
Context ic = new InitialContext();
System.out.println("about to look up jndi name " + jndiName);
Object obj = ic.lookup(jndiName);
System.out.println("lookup returned " + obj);
FooRemote foo = (FooRemote) obj;
String s = foo.echo("Hello Foo on JBoss!");
System.out.println(foo + " echo returned " + s);
}
}
Compile using the command
C:\simple-ejb3\classes>javac-d . -classpath D:\jboss-4.0.4.GA\client\jbossall-c
lient.jar;D:\jboss-4.0.4.GA\client\jboss-ejb3x.jar;D:\jboss-4.0.4.GA\server\defa
ult\lib\*.jar;D:\jboss-4.0.4.GA\lib\*.jar;.C:\simple-ejb3\src\foo\*.java
Start Jboss from bin
C:\simple-ejb3\classes>%JBOSS_HOME%\bin\run.bat
Create and deploy jar in Jboss deploy
C:\simple-ejb3\classes>jarcvf D:\jboss-4.0.4.GA\server\default\deploy\foo-ejb.j
arfoo\FooBean.class foo\FooRemote.class
7. Prepare jndi.properties and log4j.properties somewhere inclient classpath, e.g., In simple-ejb3\classes directory: create files
jndi.properties:
----------------
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
log4j.properties:
-----------------
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
Run ejb client
C:\simple-ejb3\classes>java-cp D:\jboss-4.0.4.GA\lib\*;D:\jboss-4.0.4.GA\client
\*;D:\jboss-4.0.4.GA\server\default\lib\*;.foo.Client
about to look upjndi name FooBean/remote
lookup returnedjboss.j2ee:jar=foo-ejb.jar,name=FooBean,service=EJB3
jboss.j2ee:jar=foo-ejb.jar,name=FooBean,service=EJB3echo returned Hello Foo on
JBoss!
Done
On Jboss server
14:59:54,703INFO [EJBContainer] STARTED EJB: foo.FooBean ejbName: FooBean
14:59:54,718INFO [EJB3Deployer] Deployed: file:/D:/jboss-4.0.4.GA/server/defau
lt/deploy/foo-ejb.jar
Link http://javahowto.blogspot.com/2007/11/simple-ejb-3-on-jboss-application.html
Make Directory :
C:\simple-ejb3> & C:\simple-ejb3\classes> & C:\simple-ejb3\src\foo>
C:\simple-ejb3> tree /A /F
+---classes
| \---foo
\---src
\---foo
Client.java
FooBean.java
FooRemote.java
---------------
FooRemote.java:
---------------
package foo;
import javax.ejb.*;
@Remote
public interface FooRemote {
public String echo(String s);
}
-------------
FooBean.java:
-------------
package foo;
import javax.ejb.*;
@Stateless
public class FooBean implements FooRemote {
public String echo(String s) {
return s;
}
}
-----------
Client.java
-----------
package foo;
import javax.ejb.*;
import javax.naming.*;
public class Client {
public static void main(String[] args) throws Exception {
//JBoss' default remote jndi: <ejb-name>/remote
final String jndiName = "FooBean/remote";
Context ic = new InitialContext();
System.out.println("about to look up jndi name " + jndiName);
Object obj = ic.lookup(jndiName);
System.out.println("lookup returned " + obj);
FooRemote foo = (FooRemote) obj;
String s = foo.echo("Hello Foo on JBoss!");
System.out.println(foo + " echo returned " + s);
}
}
Compile using the command
C:\simple-ejb3\classes>javac-d . -classpath D:\jboss-4.0.4.GA\client\jbossall-c
lient.jar;D:\jboss-4.0.4.GA\client\jboss-ejb3x.jar;D:\jboss-4.0.4.GA\server\defa
ult\lib\*.jar;D:\jboss-4.0.4.GA\lib\*.jar;.C:\simple-ejb3\src\foo\*.java
Start Jboss from bin
C:\simple-ejb3\classes>%JBOSS_HOME%\bin\run.bat
Create and deploy jar in Jboss deploy
C:\simple-ejb3\classes>jarcvf D:\jboss-4.0.4.GA\server\default\deploy\foo-ejb.j
arfoo\FooBean.class foo\FooRemote.class
7. Prepare jndi.properties and log4j.properties somewhere inclient classpath, e.g., In simple-ejb3\classes directory: create files
jndi.properties:
----------------
java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory
java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces
java.naming.provider.url=localhost:1099
log4j.properties:
-----------------
# Set root category priority to INFO and its only appender to CONSOLE.
log4j.rootCategory=INFO, CONSOLE
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.Threshold=INFO
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=- %m%n
Run ejb client
C:\simple-ejb3\classes>java-cp D:\jboss-4.0.4.GA\lib\*;D:\jboss-4.0.4.GA\client
\*;D:\jboss-4.0.4.GA\server\default\lib\*;.foo.Client
about to look upjndi name FooBean/remote
lookup returnedjboss.j2ee:jar=foo-ejb.jar,name=FooBean,service=EJB3
jboss.j2ee:jar=foo-ejb.jar,name=FooBean,service=EJB3echo returned Hello Foo on
JBoss!
Done
On Jboss server
14:59:54,703INFO [EJBContainer] STARTED EJB: foo.FooBean ejbName: FooBean
14:59:54,718INFO [EJB3Deployer] Deployed: file:/D:/jboss-4.0.4.GA/server/defau
lt/deploy/foo-ejb.jar
Link http://javahowto.blogspot.com/2007/11/simple-ejb-3-on-jboss-application.html
No comments:
Post a Comment