1

I'm using Netbeans to get to know Java EE. I use 'insert code' and 'call enterprise bean' to get a remote bean of which the interface is in a library included in my project. If my project is a web application netbeans, doing this inserts a function like the following. (This is a jndi lookup, correct?)

private CategoryBeanRemote lookupCategoryBeanRemote() {
    try {
        Context c = new InitialContext();
        return (CategoryBeanRemote) c.lookup("java:global/Shop2-ear/Shop2-database-ejb/CategoryBean!shop2.database.CategoryBeanRemote");
    } catch (NamingException ne) {
        Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
        throw new RuntimeException(ne);
    }
}

When you do the same in a Enterprise application client netbeans just gives

@EJB
private static BeverageBeanRemote beverageBean;

Why is this?

Is it normal that if I try to make the second one by hand in the web application, the server gives an error like this:

SEVERE: Unexpected error occurred
org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor 'public com.myapp.wicket.HomePage()'. Might be it doesn't exist, may be it is not visible (public).  
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:193)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:66)
at org.apache.wicket.DefaultMapperContext.newPageInstance(DefaultMapperContext.java:133)
...
Caused by:
java.lang.reflect.InvocationTargetException     
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
at org.apache.wicket.session.DefaultPageFactory.newPage(DefaultPageFactory.java:174)
... 40 more Caused by: java.lang.NullPointerException
at com.myapp.wicket.HomePage.<init>(HomePage.java:27) 
... 45 more
Kat
  • 668
  • 2
  • 11
  • 24

1 Answers1

0

In Java EE really important thing is configuration. Unfortunately it is really hard too learn how to configure your application correctly when you're using IDE (but without IDE it's probably harder :P)

I'm not an expert but...

My guess is that when you have created client application you bound it to some enterprise application. It was saved in configuration files. This way Client Application "knows" where is Remote Bean... and jndi lookup is not necessary.

I suggest to use some tutorial (this way you probably will know what happens behind the scene) and/or create repository like SVN and after every operation made by IDE check what has changed in configurations files.

Besides it seems to me that you haven't print full stacktrace... but maybe I'm wrong

zimi
  • 1,586
  • 12
  • 27