This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes exception in first ejb 3.1 program on NetBean 6.1 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "exception in first ejb 3.1 program on NetBean 6.1" Watch "exception in first ejb 3.1 program on NetBean 6.1" New topic
Author

exception in first ejb 3.1 program on NetBean 6.1

pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi
This is my first program of EJB in NetBeans 6.1 .When i build and run the project ,it does not show the output .Please help me to solve this.

My remote interface

package p1;

import javax.ejb.Remote;

@Remote
public interface HelloUserBeanRemote {
public void sayHello(String name);
}



My Bean is
package p1;

import javax.ejb.Stateless;

@Stateless
public class HelloUserBeanBean implements HelloUserBeanRemote {

public void sayHello(String name)
{System.out.println("Hello"+name+"welcome to EJB 3.1");
}

}


My client code is
import p1.*;
import javax.ejb.EJB;
public class Main {

@EJB
private HelloUserBeanRemote hellouser;
public void hello()
{
hellouser.sayHello("Mr. Pradeep");
}
public static void main(String[] args) {
Main a=new Main();
a.hello();

}




But when i build and run the project it shows these:
pre-init:
init-private:
init-userdir:
init-user:
init-project:
do-init:
post-init:
init-check:
init:
deps-jar:
deps-j2ee-archive:
init:
init:
deps-jar:
compile:
library-inclusion-in-manifest:
dist-ear:
deps-jar:
compile:
library-inclusion-in-manifest:
dist-ear:
init:
deps-jar:
compile:
library-inclusion-in-manifest:
dist-ear:
pre-pre-compile:
pre-compile:
do-compile:
post-compile:
compile:
pre-dist:
do-dist-without-manifest:
do-dist-with-manifest:
post-dist:
dist:
pre-run-deploy:
Incrementally deploying EJB_1_localhost:4848_server
Completed incremental distribution of EJB_1
post-run-deploy:
run-deploy:
run-display-browser:
run-ac:
Copying 1 file to E:\pradeep 25-8-8\java practice\NetBeans 6.1 programs\EJB_1\dist
28-Sep-2008 09:02:59 com.sun.enterprise.appclient.MainWithModuleSupport <init>
WARNING: ACC003: Application threw an exception.
com.sun.enterprise.InjectionException: Exception attempting to inject Resolved Ejb-Ref ejb_1.Main/hellouser@jndi: p1.HelloUserBeanRemote - > HelloUserBeanBean into class ejb_1.Main
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:387)
at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:206)
at com.sun.enterprise.util.InjectionManagerImpl.injectClass(InjectionManagerImpl.java:144)
at com.sun.enterprise.util.InjectionManagerImpl.injectClass(InjectionManagerImpl.java:136)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:420)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)
Caused by: com.sun.enterprise.InjectionException: Injected field private p1.HelloUserBeanRemote ejb_1.Main.hellouser on Application Client class class ejb_1.Main must be declared static
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:313)
... 6 more
Exception in thread "main" java.lang.RuntimeException: com.sun.enterprise.InjectionException: Exception attempting to inject Resolved Ejb-Ref ejb_1.Main/hellouser@jndi: p1.HelloUserBeanRemote - > HelloUserBeanBean into class ejb_1.Main
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:487)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)
Caused by: com.sun.enterprise.InjectionException: Exception attempting to inject Resolved Ejb-Ref ejb_1.Main/hellouser@jndi: p1.HelloUserBeanRemote - > HelloUserBeanBean into class ejb_1.Main
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:387)
at com.sun.enterprise.util.InjectionManagerImpl.inject(InjectionManagerImpl.java:206)
at com.sun.enterprise.util.InjectionManagerImpl.injectClass(InjectionManagerImpl.java:144)
at com.sun.enterprise.util.InjectionManagerImpl.injectClass(InjectionManagerImpl.java:136)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:420)
... 2 more
Caused by: com.sun.enterprise.InjectionException: Injected field private p1.HelloUserBeanRemote ejb_1.Main.hellouser on Application Client class class ejb_1.Main must be declared static
at com.sun.enterprise.util.InjectionManagerImpl._inject(InjectionManagerImpl.java:313)
... 6 more
Java Result: 1
run-EJB_1-app-client:
run:
BUILD SUCCESSFUL (total time: 27 seconds)

[ September 27, 2008: Message edited by: pradeep singh ]

SCJP 5.0(75%), SCWCD 5.0(88%)
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

You are trying to run the client inside a Application clinet Container, right? Dependency injection on client applications work only on static variables. hellouser must be declared static.


SCJP 1.4 (88%) - SCJP 5.0 Upgrade (93%) - SCWCD 1.4 (97%) - SCBCD 5.0 (98%)
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi
When i used static then it shows this

init:
init:
deps-jar:
compile:
library-inclusion-in-archive:
Building jar: E:\pradeep 25-8-8\java practice\NetBeans 6.1 programs\EJB_1\EJB_1-ejb\dist\EJB_1-ejb.jar
dist:
deps-jar:
compile:
library-inclusion-in-archive:
Copying 1 file to E:\pradeep 25-8-8\java practice\NetBeans 6.1 programs\EJB_1\EJB_1-app-client\build\jar\META-INF\lib
Building jar: E:\pradeep 25-8-8\java practice\NetBeans 6.1 programs\EJB_1\EJB_1-app-client\dist\EJB_1-app-client.jar
dist:
pre-run-deploy:
Redeploying E:\pradeep 25-8-8\java practice\NetBeans 6.1 programs\EJB_1\EJB_1-app-client\dist\EJB_1-app-client.jar
Start registering the project's server resources
Finished registering server resources
While redeploying, trying to stop the application in target server completed successfully
While redeploying, trying to remove reference for application in target server completed successfully
deployment started : 0%
deployment finished : 100%
Deploying application in domain completed successfully
Trying to create reference for application in target server completed successfully
Trying to start application in target server completed successfully
Deployment of application EJB_1-app-client completed successfully
All operations completed successfully
Enable of EJB_1-app-client in target server completed successfully
Enable of application in all targets completed successfully
All operations completed successfully
post-run-deploy:
run-deploy:
Copying 1 file to E:\pradeep 25-8-8\java practice\NetBeans 6.1 programs\EJB_1\EJB_1-app-client\dist
run-tool:
in main method
29-Sep-2008 13:01:44 com.sun.enterprise.appclient.MainWithModuleSupport <init>
WARNING: ACC003: Application threw an exception.
java.lang.NullPointerException
at ejb_1.Main.hello(Main.java:17)
at ejb_1.Main.main(Main.java:24)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:266)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:449)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)
Exception in thread "main" java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:461)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:259)
at com.sun.enterprise.appclient.Main.main(Main.java:200)
Caused by: java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.sun.enterprise.util.Utility.invokeApplicationMain(Utility.java:266)
at com.sun.enterprise.appclient.MainWithModuleSupport.<init>(MainWithModuleSupport.java:449)
... 2 more
Caused by: java.lang.NullPointerException
at ejb_1.Main.hello(Main.java:17)
at ejb_1.Main.main(Main.java:24)
... 8 more
Java Result: 1
run-jar:
run-display-browser:
run:
BUILD SUCCESSFUL (total time: 16 seconds)
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Hi Pradeep,


Can you post the Bean class (in its last version) ?
This looks more like a programming failure.

Regards,
M
[ September 29, 2008: Message edited by: Mihai Radulescu ]

SCJP, SCJD, SCWCD, OCPJBCD
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi
Mihai Radulescu
My bean class was the same as previous one.No change in that.
Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 916

Pradeep,

I mean the main class, if you look in the stack trace on the end you'll get somethinh like :


Caused by: java.lang.NullPointerException
at ejb_1.Main.hello(Main.java:17)
at ejb_1.Main.main(Main.java:24)


please post the Main class.
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi Mihai

Main class i.e. client is below:

import p1.*;
import javax.ejb.EJB;
public class Main {

@EJB
private HelloUserBeanRemote hellouser;
public void hello()
{
hellouser.sayHello("Mr. Pradeep");
}
public static void main(String[] args) {
Main a=new Main();
a.hello();

}
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Pradeep,
make sure that,

1) After making jar file for Bean class, when you deploy, it appears under Web-App module.

2) Also make sure when you are compiling your main class under NetBeans, it do has link to your EJB project (it means your Client project and has the package src of EJB project- means they should be on the same Java Build Classpath)

Hope this helps you,.


SCJP 1.4, SCWCD 5, SCBCD 5, OCPJWSD 5,SCEA-1, Started Assignment Part 2
My blog- http://rkydesigns.blogspot.com
Sergio Tridente
Ranch Hand

Joined: Mar 22, 2007
Posts: 329

Have you tried the following:


import p1.*;
import javax.ejb.EJB;
public class Main {

@EJB
static private HelloUserBeanRemote hellouser;
public void hello()
{
hellouser.sayHello("Mr. Pradeep");
}
public static void main(String[] args) {
Main a=new Main();
a.hello();

}
Juan Handal
Greenhorn

Joined: Jan 25, 2005
Posts: 29
Pradeep


Try this example ,just for your question.

Also try EJB 3 Developer Guide by Michael Sikora PACKT press 2008.


http://www.netbeans.org/kb/61/javaee/entappclient.html
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi Sergio Tridente
I have already used static keyword but same exceptions as above.
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi Juan Handal
Again same exceptions generated as above.
Please help me somebody.
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Pradeep, did you verified as per my suggstion?
pradeep singh
Ranch Hand

Joined: Oct 23, 2007
Posts: 339
Hi Amandeep Singh
First one is satisfied but dont know about second condition .Could you tell me in detail about second condition and How to achieve that also?
Amandeep Singh
Ranch Hand

Joined: Jul 17, 2008
Posts: 844
Pradeep Singh (Singh is King)

I got this site http://www.webagesolutions.com/knowledgebase/javakb/jkb005/index.html
useful for setting eclipse or NetBeans env.

Plese use the instructions given on this site to verify for your second step.

Cheers
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exception in first ejb 3.1 program on NetBean 6.1
 
Similar Threads
deployment descriptor (ejb-jar.xml) problem
Problem with EJB 3. Name not bound error
unable to find remote interface,shows exception of NoClassDefFoundError
Help needed to deploy HelloWorld EJB
Problem with code