• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

exception in first ejb 3.1 program on NetBean 6.1

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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)

 
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Mihai Radulescu
My bean class was the same as previous one.No change in that.
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();

}

 
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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,.
 
Sergio Tridente
Ranch Hand
Posts: 329
Oracle Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();

}

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Sergio Tridente
I have already used static keyword but same exceptions as above.
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Juan Handal
Again same exceptions generated as above.
Please help me somebody.
 
Amandeep Singh
Ranch Hand
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Pradeep, did you verified as per my suggstion?
 
pradeep singh
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 856
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
A wop bop a lu bop a womp bam boom! Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic