You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@geronimo.apache.org by beyondjusitn <be...@gmail.com> on 2007/12/04 14:47:51 UTC

Exception in thread "main" java.lang.NullPointerException?

I followed the 5-minute Tutorial on Enterprise Application Development with
Eclipse and Geronimo. And in my web client the EJB works fine. However, when
I tested it in my application client, as following:
public class Main{
        @EJB
	private static RemoteBusinessInterface remoteBusinessIntf;
	public static void main(String[] args) {
                 System.out.println(remoteBusinessIntf.sayHello("justin"));
	}
I got this error:Exception in thread "main" java.lang.NullPointerException.
Can anyone help me out?
Thanks a lot.

-----
--
Best Wishes!
Justin Tsao
-- 
View this message in context: http://www.nabble.com/Exception-in-thread-%22main%22-java.lang.NullPointerException--tf4943169s134.html#a14150835
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Exception in thread "main" java.lang.NullPointerException?

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Dec 4, 2007 2:47 PM, beyondjusitn <be...@gmail.com> wrote:

> I followed the 5-minute Tutorial on Enterprise Application Development with
> Eclipse and Geronimo. And in my web client the EJB works fine. However, when
> I tested it in my application client, as following:
> public class Main{
>         @EJB
>         private static RemoteBusinessInterface remoteBusinessIntf;
>         public static void main(String[] args) {
>                  System.out.println(remoteBusinessIntf.sayHello("justin"));
>         }
> I got this error:Exception in thread "main" java.lang.NullPointerException.

I have never worked with Java EE application clients in Geronimo so I
can't explain how it should be exactly, but I think you need to run it
with bin\client.jar and appropriate module id. See
http://www.ibm.com/developerworks/opensource/library/os-ag-client/ for
more information (it could be outdated slightly, but the concepts are
similar).

I can't test it out myself now, so if you run across any issues with
it, just let us know and we'll take care of it (you should even expect
another 5-minute tutorial or so ;-)).

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl

Re: Exception in thread "main" java.lang.NullPointerException?

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Dec 5, 2007 12:02 PM, Johannes Lietz
<rm...@rmail.dadabase.de> wrote:

> If you want to use them with a plain standard Java application (that's what
> I think you want to do?), there's not a defined and easy way to do it.
> WebSphere has something like that
> (http://www-128.ibm.com/developerworks/websphere/library/techarticles/0409_bhogal/0409_bhogal.html),
> but I don't know about Geronimo.

I didn't mean to post it before I finish writing the yet another
5-minute tutorial, but your comment has encouraged me to step forward
and comment on your comment ;-)

There *is* a standard approach to remote clients in javaee sense -
it's the concept of the application client where it differs from a
remote standalone client that it *is* under the dependency injection
mechanism umbrella, i.e. using annotations to declare application deps
work. It works fine on Geronimo too. I'm polishing an article about it
and once it's finished (nearly done) I'll publish it. It's based on
the 5-minute tutorial Johannes pointed out so it's assumed to require
less time than the proverbial 5 minutes.

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl

Re: Exception in thread "main" java.lang.NullPointerException?

Posted by beyondjusitn <be...@gmail.com>.
Thanks. Yeah, I've done the 5-minute tutorial. I have working web client
already.

What if what I want is an Java EE application client project in the same EAR
project just as my EJB project is in. So it will turn out that my EAR
project has an EJB project, as created in the 5-minutes tutorial, and a
client application client project. Is that possible if I want to use the
EJB's remote method in my application client? If it is, then how?

Thanks again.

Johannes Lietz wrote:
> 
> 
> EJB is meant to run as a service inside JavaEE-Servers to serve e.g. a web
> application inside the server or a number of coupled servers. In general
> you won't expose EJBs directly to a standard java remote client
> application.
> 
> I guess you've done this tutorial already?
> http://cwiki.apache.org/GMOxSAMPLES/5-minute-tutorial-on-enterprise-application-development-with-eclipse-and-geronimo.html
> 
> Then you've got your working client already, namely the MyServlet.class!
> 
> If you want to use them with a plain standard Java application (that's
> what
> I think you want to do?), there's not a defined and easy way to do it.
> WebSphere has something like that
> (http://www-128.ibm.com/developerworks/websphere/library/techarticles/0409_bhogal/0409_bhogal.html),
> but I don't know about Geronimo.
> 
> The best way to do what you want to do is to build webservice around your
> EJBs, e.g. with SOAP, RMI or similar technologies.
> 
> -Johannes
> 
> 


-----
--
Best Wishes!
Justin Tsao
-- 
View this message in context: http://www.nabble.com/Exception-in-thread-%22main%22-java.lang.NullPointerException--tf4943169s134.html#a14169775
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Exception in thread "main" java.lang.NullPointerException?

Posted by Johannes Lietz <rm...@rmail.dadabase.de>.
EJB is meant to run as a service inside JavaEE-Servers to serve e.g. a web
application inside the server or a number of coupled servers. In general
you won't expose EJBs directly to a standard java remote client
application.

I guess you've done this tutorial already?
http://cwiki.apache.org/GMOxSAMPLES/5-minute-tutorial-on-enterprise-application-development-with-eclipse-and-geronimo.html

Then you've got your working client already, namely the MyServlet.class!

If you want to use them with a plain standard Java application (that's what
I think you want to do?), there's not a defined and easy way to do it.
WebSphere has something like that
(http://www-128.ibm.com/developerworks/websphere/library/techarticles/0409_bhogal/0409_bhogal.html),
but I don't know about Geronimo.

The best way to do what you want to do is to build webservice around your
EJBs, e.g. with SOAP, RMI or similar technologies.

-Johannes


On Tue, 4 Dec 2007 20:48:20 -0800 (PST), beyondjusitn
<be...@gmail.com> wrote:
> 
> Then, how can I make it to access the remote EJB interface in my
> application
> client? I would really appreciate if you could write an step-by-step
> tutorial to me, of course use eclipse and Geronimo. I'm totally desperate
> now.
> Thanks a lot!
> 
> Johannes Lietz wrote:
>>
>>
>> Simply said: You can't just add a main method to an EJB class and expect
>> it
>> to run in the same way as it would inside an application server.
>>
>> You need the whole infrastructure an application server provides, which
>> does a lot of things behind the scenes. In your class, the server would
>> "magically" instantiate an object for your member remoteBusinessIntf,
>> which
>> will do a sayHello(). In your case remoteBusinessIntf is null, and the
>> error is thrown.
>>
>> -Johannes
>>
>>
>>
>>
> 
> 
> -----
> --
> Best Wishes!
> Justin Tsao
> --
> View this message in context:
>
http://www.nabble.com/Exception-in-thread-%22main%22-java.lang.NullPointerException--tf4943169s134.html#a14165282
> Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Exception in thread "main" java.lang.NullPointerException?

Posted by beyondjusitn <be...@gmail.com>.
Then, how can I make it to access the remote EJB interface in my application
client? I would really appreciate if you could write an step-by-step
tutorial to me, of course use eclipse and Geronimo. I'm totally desperate
now. 
Thanks a lot!

Johannes Lietz wrote:
> 
> 
> Simply said: You can't just add a main method to an EJB class and expect
> it
> to run in the same way as it would inside an application server.
> 
> You need the whole infrastructure an application server provides, which
> does a lot of things behind the scenes. In your class, the server would
> "magically" instantiate an object for your member remoteBusinessIntf,
> which
> will do a sayHello(). In your case remoteBusinessIntf is null, and the
> error is thrown.
> 
> -Johannes
> 
> 
> 
> 


-----
--
Best Wishes!
Justin Tsao
-- 
View this message in context: http://www.nabble.com/Exception-in-thread-%22main%22-java.lang.NullPointerException--tf4943169s134.html#a14165282
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Exception in thread "main" java.lang.NullPointerException?

Posted by Johannes Lietz <rm...@rmail.dadabase.de>.
Simply said: You can't just add a main method to an EJB class and expect it
to run in the same way as it would inside an application server.

You need the whole infrastructure an application server provides, which
does a lot of things behind the scenes. In your class, the server would
"magically" instantiate an object for your member remoteBusinessIntf, which
will do a sayHello(). In your case remoteBusinessIntf is null, and the
error is thrown.

-Johannes


On Tue, 4 Dec 2007 07:23:22 -0800 (PST), beyondjusitn
<be...@gmail.com> wrote:
> 
> Sorry, but could you be more specific? You know, I'm rather naive, very
> new
> to Java EE. Could you write something like 5-minutes tutorial?
> 
> Thanks a lot.
> 
> Jacek Laskowski wrote:
>>
>> On Dec 4, 2007 2:47 PM, beyondjusitn <be...@gmail.com> wrote:
>>>
>>> I followed the 5-minute Tutorial on Enterprise Application Development
>>> with
>>> Eclipse and Geronimo. And in my web client the EJB works fine. However,
>>> when
>>> I tested it in my application client, as following:
>>> public class Main{
>>>         @EJB
>>>         private static RemoteBusinessInterface remoteBusinessIntf;
>>>         public static void main(String[] args) {
>>>
>>> System.out.println(remoteBusinessIntf.sayHello("justin"));
>>>         }
>>> I got this error:Exception in thread "main"
>>> java.lang.NullPointerException.
>>
>> I've realized I didn't answer your question, so here it goes again. It
>> won't work unless you're using the concept of javaee5 application
>> client where DI (dependency injection) works. You should deploy your
>> application with an application client and run client.jar with the
>> module id of the application you deploy. It should be clearer now ;-)
>>
>> Jacek
>>
>> --
>> Jacek Laskowski
>> http://www.JacekLaskowski.pl
>>
>>
> 
> 
> -----
> --
> Best Wishes!
> Justin Tsao
> --
> View this message in context:
>
http://www.nabble.com/Exception-in-thread-%22main%22-java.lang.NullPointerException--tf4943169s134.html#a14152277
> Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Exception in thread "main" java.lang.NullPointerException?

Posted by beyondjusitn <be...@gmail.com>.
Sorry, but could you be more specific? You know, I'm rather naive, very new
to Java EE. Could you write something like 5-minutes tutorial?

Thanks a lot.

Jacek Laskowski wrote:
> 
> On Dec 4, 2007 2:47 PM, beyondjusitn <be...@gmail.com> wrote:
>>
>> I followed the 5-minute Tutorial on Enterprise Application Development
>> with
>> Eclipse and Geronimo. And in my web client the EJB works fine. However,
>> when
>> I tested it in my application client, as following:
>> public class Main{
>>         @EJB
>>         private static RemoteBusinessInterface remoteBusinessIntf;
>>         public static void main(String[] args) {
>>                 
>> System.out.println(remoteBusinessIntf.sayHello("justin"));
>>         }
>> I got this error:Exception in thread "main"
>> java.lang.NullPointerException.
> 
> I've realized I didn't answer your question, so here it goes again. It
> won't work unless you're using the concept of javaee5 application
> client where DI (dependency injection) works. You should deploy your
> application with an application client and run client.jar with the
> module id of the application you deploy. It should be clearer now ;-)
> 
> Jacek
> 
> -- 
> Jacek Laskowski
> http://www.JacekLaskowski.pl
> 
> 


-----
--
Best Wishes!
Justin Tsao
-- 
View this message in context: http://www.nabble.com/Exception-in-thread-%22main%22-java.lang.NullPointerException--tf4943169s134.html#a14152277
Sent from the Apache Geronimo - Users mailing list archive at Nabble.com.


Re: Exception in thread "main" java.lang.NullPointerException?

Posted by Jacek Laskowski <ja...@laskowski.net.pl>.
On Dec 4, 2007 2:47 PM, beyondjusitn <be...@gmail.com> wrote:
>
> I followed the 5-minute Tutorial on Enterprise Application Development with
> Eclipse and Geronimo. And in my web client the EJB works fine. However, when
> I tested it in my application client, as following:
> public class Main{
>         @EJB
>         private static RemoteBusinessInterface remoteBusinessIntf;
>         public static void main(String[] args) {
>                  System.out.println(remoteBusinessIntf.sayHello("justin"));
>         }
> I got this error:Exception in thread "main" java.lang.NullPointerException.

I've realized I didn't answer your question, so here it goes again. It
won't work unless you're using the concept of javaee5 application
client where DI (dependency injection) works. You should deploy your
application with an application client and run client.jar with the
module id of the application you deploy. It should be clearer now ;-)

Jacek

-- 
Jacek Laskowski
http://www.JacekLaskowski.pl