简体   繁体   中英

How to create EJB and client(plain java program) in different JVMs

I need to create EJB and a plain java program(client) in different JVMs and get them executed. How should I do this using NETBeans IDE in my system.

It seems to me that you are looking for a Java EE Application Client. Basically you have your Java EE container, where your EJBs live, running in one JRE instance (your Application Server Java process) and you need a standalone java application to be able to communicate with your EJBs.

Creating the Java EE Application Client

You will need to create the EJB firstly, plenty of examples around for that, but basically create an interface with (@Remote) and an implementation bean (@Stateless for eg.)

Then you will need an Application server to deploy or test the EJB, you can use NetBeans to start a debuggable instance of an Integrated Enterprise Application Server (Like JBOSS), plenty of examples around of those too, once that is done, you can simply create a test class (in NetBeans and do a remote jndi lookup (to localhost) in your test class) Your instance of the Appliction server will run another JVM, and your test class (should probably have a main method, or create a junit test, even better to test it :-)) will run in it's own JVM.

So you need an EJB (packaged and deployed (can do through Netbeans)), an Application Server (to deploy the EJB), running in an instance (Netbeans or stand alone) And the test class that will perform the remote lookup and invoke any of your EJB"s methods.

This you can all do from your "system" - localhost.

NetBeans already starts different applications in different JVM processes (java.exe).

You just need to deploy your ejb-jars in different server instances (which are containers for your EJBs).

Also, if you deploy your jars in different EAR's in the same server (other than JBoss) they will be loaded by different classloaders, meaning they won't be able to interact very well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM