2

So I have a simple ejb (@stateless) deployed on a glassfish 3.1 server.

I want to call it from a standalone application.

It's working great if I add the gf-client.jar into my run configuration.

But how can I do if I do not have that file (the server is in another machine) ?

I tried using

<dependency>
  <groupId>org.glassfish.common</groupId>
  <artifactId>glassfish-naming</artifactId>
  <version>LATEST</version>
</dependency>

But I have

Exception in thread "main" javax.naming.NameNotFoundException: java:global
at com.sun.enterprise.naming.impl.TransientContext.resolveContext(TransientContext.java:252)
at com.sun.enterprise.naming.impl.TransientContext.lookup(TransientContext.java:171)
at com.sun.enterprise.naming.impl.SerialContextProviderImpl.lookup(SerialContextProviderImpl.java:58)
at com.sun.enterprise.naming.impl.LocalSerialContextProviderImpl.lookup(LocalSerialContextProviderImpl.java:95)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:233)
at javax.naming.InitialContext.lookup(Unknown Source)
at be.java.tuto.Application.main(Application.java:17)

Thanks.

tweetysat
  • 2,187
  • 14
  • 38
  • 75

1 Answers1

0

EDIT:

I just needed to invoke an EJB deployed on GF from my Tomcat server and resurrected my dependencies. And because I dont want to keep them back for myself :)... minimal dependencies for gf bean invokation

My IDE is Eclipse so I created an User Library containing all the files shown above.

Hope this solves your problem!


I was facing the same problem. For just wanting to invoke a GF session-Bean method I had to add the complete gf-client.jar to my clients classpath.

My problem was that this library is referencing almost the whole GF-libray-folder and even after a clean-up there were >15 referenced jars left which I had to add to my clients classpath.

For me I did't want this overhead so I decided to call the remote method via JAX-WS webservice.

The advantage of using webservises is that it is very easy to add webservice capability to an already existing session-bean by annotating the bean-class with @WebService.

After publishing the bean to the appserver you're able to view your deployed endpoint and getting the WSDL. With this you can generate your webservice-stubs automatically by using the wsimport-tool shipped with your JDK and use this generated files in yor client to invoke the remote method.

See example here.

Once created those files are portable and can be used in any client.

So if your willing to change the way your client calls the remote method this would be a portable, lightweight (except of a bit more http overhead) and easy to implement alternative.

P.S. You don't lose the ability of invoking your method via EJB-call.

Hope this helped, have Fun!

SimonSez
  • 7,399
  • 1
  • 30
  • 35
  • The only downside of this is that the semantics of the call are different. With a EJB you can send any serializable Java object, and this is not the case with a web service. For example, the default JAX-WS tools won't all you to send a graph of object (say an object containing another object that has a reference to the parent). This can be worked around, but it's something to be aware of. – Will Hartung Mar 10 '12 at 00:07
  • Sorry to hear! And your right: There is no solution of invoking a GF-Bean without adding the *gf-client*-file (**and** its referencing jars) to your clients classpath :(. Therefore I suggested the WebService approach. Cheers! – SimonSez Mar 12 '12 at 14:30
  • Ok thanks, I understand. But the problem was not invoking a GF-Bean without adding the gf-client-file but findind a maven dependency for the gf-client-file. My glassfish server is on a machine and I'm developping on another. So I don't have the gf-client-file. I tried your solution but it's quite more difficult to understand ... See [link](http://stackoverflow.com/questions/9668583/invoke-soap-webservice-returning-list-of-objects-from-java-client-with-axis#comment12280773_9668583) – tweetysat Mar 13 '12 at 07:02
  • Oh, now I understand. For myself I don't work with maven but I took a quick look and found those links for a maven [repository](http://search.maven.org/#search|ga|1|gf-client) and someone on [Stack Overflow](http://stackoverflow.com/questions/5675024/with-which-maven-dependencies-can-i-create-a-standalone-jms-client-for-glassfish) facing a similar problem (take a look in his answer, he describes how he solved it for a bean call and gave a link to a minimum dependencies list). Cheers! – SimonSez Mar 13 '12 at 09:01