This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes EJB and other Java EE Technologies and the fly likes Ejb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Ejb" Watch "Ejb" New topic
Author

Ejb

vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
Hello all,
i have ejb program consists of following files:
in Hello directory
HelloHome
package Hello;
import javax.ejb.EJBHome;
import javax.ejb.CreateException;
import java.rmi.RemoteException;

public interface HelloHome extends javax.ejb.EJBHome
{
Hello.HelloInterFace create() throws
java.rmi.RemoteException,
javax.ejb.CreateException;
}

Hello Bean
package Hello;

import javax.ejb.SessionContext;

public class HelloBean implements javax.ejb.SessionBean
{
private SessionContext ctx;

public void ejbCreate() {
System.out.println("You are inside ejbCreate()");
}

public void ejbRemove() {
System.out.println("You are inside ejbRemove()");
}

public void ejbActivate() {
System.out.println("You are inside ejbActivate()");
}

public void ejbPassivate() {
System.out.println("You are inside ejbPassivate()");
}

public void setSessionContext(javax.ejb.SessionContext ctx) {
this.ctx = ctx;
}


public String hello()
{
return "Hello to everyone and welcome to the Interview question series";
}
}

HelloInterface
package Hello;
import java.rmi.RemoteException;
import javax.ejb.EJBObject;
public interface HelloInterFace extends javax.ejb.EJBObject
{
public String hello() throws java.rmi.RemoteException;
}

HelloClient
package Hello;

import javax.naming.Context;
import javax.naming.InitialContext;
import java.util.Properties;


public class HelloClient {

public static void main(String[] args) throws Exception {

Properties properties = new Properties();
properties.put("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
properties.put("java.naming.factory.url.pkgs","=org.jboss.naming rg.jnp.interfaces");
properties.put("java.naming.provider.url","localhost:1099");
Context ctx = new InitialContext(properties);

System.out.println("Got context");
Object obj = ctx.lookup("hello/Hello");

System.out.println("Got reference");
HelloHome home = (HelloHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);

HelloInterFace hello = home.create();
System.out.println("Created Home object");

System.out.println(hello.hello());
System.out.println("Called the actual method");

hello.remove();
System.out.println("Removed the object from the container");
}
}

And these files are there in WEB-INF/classes/Home

And Deployment ddescriptors like

ejb-jar.xml
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<display-name>Hello</display-name>
<enterprise-beans>
<session>
<display-name>Hello</display-name>
<ejb-name>Hello</ejb-name>
<home>Hello.HelloHome</home>
<remote>Hello.HelloInterFace</remote>
<ejb-class>Hello.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

weblogic-ejb-jar.xml consists of
<?xml version="1.0"?>

<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 8.1.0 EJB//EN"
"http://www.bea.com/servers/wls810/dtd/weblogic-ejb-jar.dtd">

<!-- Sample MessageDriven bean Weblogic deployment descriptor -->

<weblogic-ejb-jar>

<weblogic-enterprise-bean>

<ejb-name>Hello</ejb-name>
<jndi-name>hello/Hello</jndi-name>
</weblogic-enterprise-bean>


</weblogic-ejb-jar>

These xml files are there in META-INF directory
please tell me how to deploy and execute this application.
Sumit Malik
Ranch Hand

Joined: Jan 05, 2007
Posts: 84
Hey Vin Hari you must have googled this option a bit but i think this link would help you.

By default wlserver/config/mydomain/applications is the location where you can deploy ejb module while server is up. wlserver is the weblogic installation directory

Cheers !!!
Sumit Malik


If at first you don't succeed, don't try skydiving
vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
Hello sir,
Thank you for you reply but sir after going through that also i did not get the answer thats why i posted you sir , sir please tell me the steps to create .jar .war .ear with respect to that example which one to create why to create and how to create,please help me sir in executing this example i dont know anything about weblogic 8.0
Sumit Malik
Ranch Hand

Joined: Jan 05, 2007
Posts: 84
Hey Vin Hari i hope this link would help you up in packaging the ejb in weblogic.

See the whenever you are deploying your componenet on j2ee complaint application server then there is a basic structure which you need to follow and then with that stucture you need to deploy your modules in the deployement directory.

Well, for more about the structure of ejb module you can go through with this link

Cheers !!!
Sumit Malik
vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
thank You sir,
but to say frankly bea website is very hard website to understand anything for the freshers,really iam feeling too complicated.
Sumit Malik
Ranch Hand

Joined: Jan 05, 2007
Posts: 84
Hey Vin Hari I can understand you but you know everyone has to start from somewhere and no one is equipped with every technical details of domain in whichever he/she is working.

I know there is always a learing curve for newbie but that is how you need to start. Once you will be regular with domain in which you are working then you gonna find its very enticing and intresting.

I wish you very best of luck...


Cheers !!!
Sumit Malik
vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
Hello summit,
Thank you for your reply really very kind of you,sir i created domain in weblogic8.0 called EJBdomain in that i pasted the Hello directory in application folder and i compiled all the java files and i created .jar file and deployed in server that was also successfull but the problem is that how to execute that client file when i did java HelloClient to run that it is showing exceptions please tell me how to execute after successfull deploy.
Sumit Malik
Ranch Hand

Joined: Jan 05, 2007
Posts: 84
Hey Vin Hari i havent explored much weblogic but if you want to call ejb interface from client then you need to get the initial context of weblogic server where you have deployed ejb...

Once you have got the initial context then you need to lookup for the remote (if your client is on another JVM from server JVM)interface or local(if you client is in the same JVM where weblogic is) interface. Once you get the initial context then you can call business method on that interface.....


I hope now you will explore more with your client code...

Cheers !!!
Sumit Malik
vin Hari
Ranch Hand

Joined: Nov 16, 2006
Posts: 161
Hello all,
at lasti was able to solve the session beans but strucked again with the entity bean how to solve.
Sumit Malik
Ranch Hand

Joined: Jan 05, 2007
Posts: 84
Hey Vin Hari thats really great you have started cracking on EJB but untill and unless you wont tell us that how you stuck up in entity beans we wont able to suggest any possible solution.

Cheers !!!
Sumit Malik
 
Don't get me started about those stupid light bulbs.
 
subject: Ejb