Search code examples
javaejb

How to call EJB from Standalone java program in diffrent JVM


I have developed EJB using NETbeans IDE having glassfish server. I can call it from standalone java, only if this java project is developed under NETbeans and run under same JRE. But I need to find out how to run it in different jre's. I could not find much help on this one. Any suggestions? (or related links would do) Thanks,


Solution

  • In order to call EJB from remote JVM, you should

    • Use @Remote annotation on you EJB

    • Supply a jar with interfaces and put it in the classpath of you client-vm

    • Use JNDI in order to obtain a reference on the EJB stub from server.

    • For JNDI you'll need an implementation that depends on container (for example, if its JBoss jboss-client-all.jar should be enough (I don't remember the exact name but you've got the point, I think)

    Once you feel comfortable with the overall notions and definitions, read this example, I think its handy enough Example

    Hope this helps