• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Here is the complete JBoss Config. for EJB

 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JBoss 3.0 Step-by-Step Tutorial by Md. Anwar Hossain and Muhammad Ashikuzzaman
==================================================
JBoss, an open source application and EJB server, is a complex tool. This article attempts to
walk the new user through the use of Jboss 3.0 from installation through the deployment
and use of a “Hello World” EJB and client application.
Using JBoss can be a daunting task for the first time. I will attempt to describe every
step of the process from installing JBoss to getting a client to calling a “Hello World”
Enterprise Java Bean from a client located on a different machine. The second
machine is not required but emphasizes the power of Enterprise Java Beans (EJB’s) and the transparency of location they can have.
Getting and Installing JBoss
Requirements:
First make sure you have a recent JDK such as 1.3 or higher. The next step is
obtaining JBoss from the JBoss website. You can find the JBoss binaries (executables) at http://www.jboss.org/downloads.jsp. At the time of writing the file to retrieve is JBoss-3.0.0.zip (jboss-3.0.0_tomcat-4.0.3.zip) with integrated Tomcat 4.0. Tomcat is the official reference implementation for servlet containers. More information about tomcat can be found at the Apache Jakarta project.
Once the file finishes downloading you need to extract the zip file to the directory of
your choice. For Windows you can use WinZip and for Linux simply use unzip at the command line to unzip the file. I chose to extract my file to: C:\jboss-3 (assume that you have extracted in C
Starting JBoss
Starting JBoss is easy, simply change to the bin directory where JBoss is installed and execute run.bat on windows or run.sh on Linux. So the sequence of commands when starting at C:\ was:
C:cd \jboss-3.0.0_tomcat-4.0.3
cd bin
run
Once I typed “run” a lot of logging information was displayed until the last line of
logging output stopped displaying:
23:01:20,309 INFO [Server] JBoss (MX MicroKernel) [3.0.0
Date:200205311035] Started in 0m:43s:973ms
Now that JBoss has been started we can test that it is up and running using the web
interface provided through the integrated version of Tomcat. Simply point your browser to http://localhost:8082/ and you should see a page titled “Agent View”.
First Steps :
Writing the HelloWorld EJB
Now we write a simple “hello world” EJB. I will presume you understand how the pieces of EJB’s fit together if not I would recommend getting Master Enterprise Java Beans,2nd Edition or see the references at the end of this tutorial. We will begin by writing the server side which is the Enterprise Java Bean.
The Server Side Enterprise Java Bean
The first class to write (in no particular order) is the interface the EJB client will interact with.
Remote Interface
We will start by coding the remote interface. These are the business methods that the client will call to perform work.
HelloWorld.java
Home Interface
The home interface acts as a factory for EJB's. The home interface is how the
container creates and destroys the EJB's used by applications.
package com.mastertech.sample;
/**
* This is the remote interface that the client calls to
* have the EJB do the work.
*/
public interface HelloWorld extends javax.ejb.EJBObject
{
public String hello() throws java.rmi.RemoteException;
}
Next Step :
Writing the HelloWorld EJB
Now we write a simple “hello world” EJB. I will presume you understand how the pieces of EJB’s fit together if not I would recommend getting Master Enterprise Java Beans,2nd Edition or see the references at the end of this tutorial. We will begin by writing the server side which is the Enterprise Java Bean.
The Server Side Enterprise Java Bean
The first class to write (in no particular order) is the interface the EJB client will interact with.
Remote Interface
We will start by coding the remote interface. These are the business methods that the client will call to perform work.
HelloWorld.java
Home Interface
The home interface acts as a factory for EJB's. The home interface is how the
container creates and destroys the EJB's used by applications.
package com.mastertech.sample;
/**
* This is the remote interface that the client calls to
* have the EJB do the work.
*/
public interface HelloWorld extends javax.ejb.EJBObject
{
public String hello() throws java.rmi.RemoteException;
}

Deployment Descriptor
The XML deployment descriptor that provides the plumbing between the container and the beans you write. Below is the deployment descriptor we will use.
ejb-jar.xml
package com.mastertech.sample;
import javax.ejb.SessionContext;
/**
* This class is the actual implementation of the business
* logic. This is the EJB for simplicity's sake.
*/
public class HelloWorldBean implements javax.ejb.SessionBean
{
private SessionContext ctx;
public void setSessionContext(SessionContext ctx)
{
this.ctx = ctx;
}
public void ejbRemove()
{
System.out.println( "ejbRemove()" );
}
public void ejbActivate()
{
System.out.println( "ejbActivate()" );
}
public void ejbPassivate()
{
System.out.println( "ejbPassivate()" )
}
/**
* The method called to display the string "Hello World!"
* on the client.
*/
public String hello()
{
System.out.println( "hello()" );
return "Hello World!";
}
}
Next Deployment Descriptor
The XML deployment descriptor that provides the plumbing between the container and the beans you write. Below is the deployment descriptor we will use.
ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar>
<description>JBoss Hello World Application</description>
<display-name>Hello World EJB</display-name>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<home>com.mastertech.sample.HelloHome</home>
<remote>com.mastertech.sample.Hello</remote>
<ejb-class>com.mastertech.sample.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>
Once the deployment descriptor is complete it needs to be put into the META-INF
directory. The META-INF directory should reside at the root of the package directory.
For this example that is in the C:\projects\jboss-test directory but yours
may be where ever your project resides. My complete project directory structure is as follows:
C:\projects\jboss-test\com
C:\projects\jboss-test\com\mastertech
C:\projects\jboss-test\com\mastertech\sample
C:\projects\jboss-test\
com\mastertech\sample\HelloWorld.class
C:\projects\jboss-test\
com\mastertech\sample\HelloWorldBean.class
C:\projects\jboss-test\
com\mastertech\sample\HelloWorldHome.class
C:\projects\jboss-test\META-INF
C:\projects\jboss-test\META-INF\ejb-jar.xml
JBoss.xml
According to the JBoss documentation the Jboss.xml file is almost never required so it will be ignored for this tutorial.
Put That Bean in a Jar!
Now the bean classes and deployment descriptor need to be placed into a jar file before we can deploy the EJB to the JBoss application server. To create the deployment jar file first change directories to the root of the project directory with:
cd C:\projects\jboss-test
Then execute the jar command to create the deployable jar file with:
jar cf HelloWorld.jar com META-INF
This will result in a file called “HelloWorld.jar” in the C:\projects\jboss-test directory.
Next Deploy HelloWorld EJB:
To deploy the HelloWorld.jar file simply copy the jar file to the JBoss deployment directory which is (on my computer)::\jboss-3\server\default\deploy
Upon deployment the servers console will change. This is what my JBoss 3.0 server displayed:
15:09:21,184 INFO [MainDeployer] Starting deployment of
package: file:/C:/jboss -3.0.0_tomcat-4.0.3/server/default/deploy/HelloWorld.jar
15:09:21,324 INFO [EjbModule] Creating
15:09:21,354 INFO [EjbModule] Deploying HelloWorld
15:09:21,464 INFO [EjbModule] Created
15:09:21,484 INFO [EjbModule] Starting
15:09:21,555 INFO [EjbModule] Started
15:09:21,555 INFO [MainDeployer] Successfully completed
deployment of package: file:/C:/jboss-3.0.0_tomcat-4.0.3/ server/default/deploy/HelloWorld.jar
When I had some errors in my ejb-jar.xml I got the following message on my Jboss console:
16:13:17,007 INFO [MainDeployer] Starting deployment of
package:
file:/C:/jboss-3.0.0_tomcat-4.0.3/server/default/deploy/HelloWorld.jar
16:13:17,027 INFO [MainDeployer] Deployment of package:
file:/C:/jboss-3.0.0_tomcat-4.0.3/Server/default/deploy/HelloWorld.jar is waiting for
an appropriate deployer.
The problem was resolved by fixing finding and fixing the problem with the ejb-jar.xml.
The Client Side
There is no point in having an EJB if we don't have a client application to you use it.
Now we need to create the client for the HelloWorld EJB we wrote. Below is the source code for a command line client that can be executed on the same machine.
HelloWorldClient.java
Once HelloWorldCLient.java is compiled you can execute it on the same machine with no changes. To execute HelloWorldClient.java on another machine you need to change the line:
env.put(Context.PROVIDER_URL, "localhost:1099");
To point to the machine that has the lookup services. On my network I simply
changed the above line to point to:
env.put(Context.PROVIDER_URL, "server.mastertech.net:1099");
For the client code to execute you need some JBoss client jar files in your class path in addition to a jar containing the remote interfaces and stubs to the HelloWorld EJB we wrote. On the machine where I ran HelloWorldClient.class I had the following in my classpath: C:\j2ee131\lib\j2ee.jar
Here is Code:
package com.mastertech.sample;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Hashtable;
public class HelloWorldClient
{
public static void main( String [] args )
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost:1099");
env.put("java.naming.factory.url.pkgs","org.jboss.naming rg.jnp.interfaces");
try
{
Context ctx = new InitialContext(env);
Object obj = ctx.lookup( "HelloWorld" );
HelloWorldHome home = (HelloWorldHome)javax.rmi.PortableRemoteObject.narrow(
obj, HelloWorldHome.class );
HelloWorld helloWorld = home.create();
System.out.println( helloWorld.hello());
helloWorld.remove();
}
catch ( Exception e )
{
e.printStackTrace();
System.out.println( "Exception: " + e.getMessage() );
} }
}

Now Compile the Client code and run:

Once HelloWorldCLient.java is compiled you can execute it on the same machine with no changes. To execute HelloWorldClient.java on another machine you need to change the line:
env.put(Context.PROVIDER_URL, "localhost:1099");
To point to the machine that has the lookup services. On my network I simply changed the above line to point to:
env.put(Context.PROVIDER_URL,"server.mastertech.net:1099");
For the client code to execute you need some JBoss client jar files in your class path in addition to a jar containing the remote interfaces and stubs to the HelloWorld EJB we wrote. On the machine where I ran HelloWorldClient.class I had the following in my classpath: C:\j2ee\lib\j2ee.jar

Installation process at a glance:
Step 1:
Assume that u’ve installed
jsdk in C:\jdk1.3\
j2eesdk in c:\j2ee
jBoss3.2_tomcat4 in c:\jboss-3
Step 2:
Setting Classpath
classpath=C:\jBoss-3\client
Step 3:
Code Compile command :
Javac -classpath C:\jBoss-3\client \client\jboss-j2ee.jar com\mastertech\sample\*.java
Step 4:
Create EJB-JAR
===============
jar cf HelloWorld.jar com META-INF
Step 5:
Copy
====
Now copy the file HelloWorld.jar file to C:\jBoss-3\client \server\default\deploy directory.
Step 6:
Client Compilation in the command prompt
Download ,,, j2ee.jar(J2eesdk) from Sun’s web site (java.sun.com)
===================
javac -classpath .;%classpath%; C:\jBoss-3\client\server\default\deploy\HelloWorld.jar; C:\jBoss-3\client \client -d . C:\EJBTest\com\mastertech\sample\HelloWorldClient.java
 
Ranch Hand
Posts: 2378
MySQL Database Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Anwar,
I already started a series on JBoss installation in another Java Site so was not posting it here.
Good that you have done it on my favor. Howerver, You should have posted it in JBoss forum of this site.
Please consider posting other application servers also (like Sun's reference implementation, WebLogic, WebSphere or Oracle9iAS), especially as you have worked with Sun's reference implementation a few days ago.
Just communicate with the community.
[ June 29, 2003: Message edited by: Ashik uzzaman ]
 
Anwar Hossain
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah Ashik,
I'll do it very soon my friend. Anyway thanks for ur precious comment.Pls carry on doing so.
Regards,
Md. Anwar Hossain
SCJP2, MCP
 
Ranch Hand
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx anwar !!
 
Anwar Hossain
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Andres,

Anwar Hossain
SCJP2,MCP
 
Anwar Hossain
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This complete config. for deploying EJB published by: ultimatix abc
greenhorn
Member # 51474
On behave of this fellow, I'ld like to publish once again for those people who r really wanna use IBM's WebLogic to implement the EJB. I'ld like to recommend u guys to use my previous EJB's "HelloWorld" example to deploy when u'll use it.
so.. Many Thx to ultimatix abc
Here are the steps to deploy EJB:
==================================================

1.Create a directory where you are going to write all your session beans(Applicable to both Stateless and stateful ).
2.If your session beans are to be in a package then a good option would be to use JCreator for compilation otherwise you have to compile always with the –d option and have to create complicated batch files with classpath settings.
3.For eg. if you have a package statement like -
package examples.SessionBeans;
Then you need to have a directory called examples inside which you need to have a directory called SessionBeans or some Name.
4.Inside the SessionBeans directory put your Home Interface, Remote Interface and Bean classes.
5.Inside the SessionBeans directory create a directory called "META-INF". Note that all the letters should be in capital.
6.In the META-INF directory put your ejb-jar.xml. This you will get along with any sample code.u can search in bea folder also.
7. You need to create another file called weblogic-ejb-jar.xml with the following lines
<?xml version="1.0"?>
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN" "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd">
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>UserSessionBean</ejb-name>
<jndi-name>UserSessionHome</jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>
The ejb name that you specify should be same as the one you specify in the ejb-jar.xml. The jndi-name is the one you should use when looking up the home from the JNDI tree.
8. Create a jar file from one level above the package structure where your class files are.
For eg. if your classes are in a package called examples.SessionBeans, the jar file should be created from one directory above the examples directory.
9.Open the jar file in winzip and make sure the directory structure is OK and the XML files are inside the META-INF directory.
10. You now need to do an ejb compilation. Though this is not mandatory it is very useful as it checks your bean’s validity. If your ejbc goes through successfully you can be sure that your bean will be deployed successfully.
The command for ejbc is as follows
java weblogic.ejbc -g -classpath %CLASSPATH% -compiler javac <src-file> <dest-file>
For ease of use, create a batch file called ejbc.bat and put the following lines in it
SET SOURCE_JAR=%1%
SET DEST_JAR=%2%
set classpath=C:\bea\weblogic700\server\lib\weblogic.jar;
java weblogic.ejbc -g -classpath %CLASSPATH% -compiler javac %SOURCE_JAR% %DEST_JAR%
Make sure the classpath is OK.
The bat file can be used as follows
ejbc <Source-bean-jar> <Source-bean-deployable-jar>
For eg.
ejbc UserBean.jar UserBeanDeployable.jar
11. You now have a Enterprise Java bean that is ready to be deployed !!!
12. In Weblogic 7.0 put the jar file created as a result of the ejbc in the following directory
C:\bea\samples\server\config\examples\applications. For Weblogic 6.0 or 6.1 there should be a similar directory called applications where you place your code.
13. Start the Weblogic server. Note that you can put the file here even after you have started the server, any files that are added to this directory are automatically deployed, any that are removed are undeployed and any file whose time stamp changes will be redeployed.
14. If you have a client that you need to run to call the methods of this bean do so with the following class file.
set classpath=.;c:\bea\weblogic700\server\lib\weblogic.jar;
java -Djava.naming.factory.initial=weblogic.jndi.TengahInitialContextFactory -Djava.naming.provider.url=t3://192.10.137.165:7001 <Client-java-class>
You can set the Initial context factory and naming provider url even inside your code if you want but this is a better way. The –D option basically sets a System property.
15.You have now deployed and tested a Session Bean
pls don't do step 10 i mean EJB COmpilation if ur a Beginner.
After ur bean will be Deployed u can check from the Console or the CMD prompt of server where ur Beans name will appear.
That's all..
=================================================
so please let me know about ur comments....
And also my friend's Muhammad Ashikuzzaman's comment.

Regards,
==========================
Md. Anwar Hossain
SCJP2, MCP
 
Whose rules are you playing by? This tiny ad doesn't respect those rules:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic