A Simple Java Client Server Application using EJB3 and Glassfish3

Well, in this tutorial i want to show you how to create a simple client server application using java. Actually java has dozens of different network protocols, from a simple socket, hessian, burlap, SpringHttpInvoker, SOAP, XML and so on. But in this example, i will try to create a very simple client server application with EJB 3, using Glassfish 3 as JavaEE Container. As usual, i use Netbeans 6.9 with its default Glassfish3 installation.

First, i create a new JavaEE, EJB Module project, named CompressedEJBServer, and create a simple Stateless Session Bean in it

package com.edw.facade;

import javax.ejb.Remote;

/**
 *
 * @author edw
 */
@Remote
public interface ConnectionFacadeRemote {
    String sayHello(String string);
    int sayAge(int age);  
}

and its implementation

package com.edw.facade;

import javax.ejb.Stateless;

/**
 *
 * @author edw
 */
@Stateless
public class ConnectionFacade implements ConnectionFacadeRemote {

    public String sayHello(String string) {
        System.out.println("im at " + this.getClass().getName() + " method sayHello()");
        return "hello " + string;
    }

    public int sayAge(int age) {
        System.out.println("im at " + this.getClass().getName() + " method sayAge()");
        return age * 2;
    }
}

and that’s my EJB3 Server side files. Simple isn’t it?

Next step is creating a Standard Java Application project, for my EJB3 client application. It consist only 1 java file, for testing connection to the server.

package com.edw.main;

import com.edw.facade.ConnectionFacadeRemote;
import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import org.apache.log4j.Logger;

/**
 *
 * @author edw
 */
public class Main {

    private Logger logger = Logger.getLogger(Main.class);

    private void connect() {
        try {
            Properties props = new Properties();
            props.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.enterprise.naming.SerialInitContextFactory");
            props.setProperty("org.omg.CORBA.ORBInitialHost", "localhost");
            
            // glassfish default port value will be 3700, 
            // but im using tcpviewer to redirect my 50005 port to 3700
            props.setProperty("org.omg.CORBA.ORBInitialPort", "50005");

            InitialContext ctx = new InitialContext(props);
            ConnectionFacadeRemote connectionFacadeRemote = (ConnectionFacadeRemote) ctx.lookup("com.edw.facade.ConnectionFacadeRemote");
            logger.debug(connectionFacadeRemote.sayHello("edwin "));
            logger.debug("my age is " + connectionFacadeRemote.sayAge(12) + " years");
        } catch (Exception ex) {
            logger.error(ex.getMessage(), ex);
        }
    }

    public static void main(String[] args) {
        Main x = new Main();
        x.connect();
    }
}

include these jars to your client side’s application,

auto-depends.jar
common-util.jar
config.jar
config-api.jar
config-types.jar
connectors-internal-api.jar
container-common.jar
deployment-common.jar
dol.jar
ejb.security.jar
ejb-container.jar
glassfish-api.jar
glassfish-corba-asm.jar
glassfish-corba-codegen.jar
glassfish-corba-csiv2-idl.jar
glassfish-corba-newtimer.jar
glassfish-corba-omgapi.jar
glassfish-corba-orb.jar
glassfish-corba-orbgeneric.jar
glassfish-naming.jar
gmbal.jar
hk2-core.jar
internal-api.jar
javax.ejb.jar
javax.jms.jar
javax.resource.jar
javax.servlet.jar
javax.transaction.jar
jta.jar
kernel.jar
management-api.jar
orb-connector.jar
orb-iiop.jar
security.jar
tiger-types-osgi.jar
transaction-internal-api.jar 

and dont forget to add CompressedEJBServer project into CompressEJBClient’s project

this is what happen if i run my client side’s application

[Main] DEBUG com.edw.main.Main:30 - hello edwin 
[Main] DEBUG com.edw.main.Main:31 - my age is 24 years

this is my Server side’s project structures

and this is my Client side’s project structures
My Client Side's Project Structure

and this is my TCP Viewer logs, i try to redirect my localhost’s port 50005 into my localhost’s port 3700 (Glassfish’s port), so i can see what is passing through my 50005 port via TCP Viewer’s console.

Hope this can help, have fun and good luck. May the Source be with You.
(*)

Google+

74 Comments

Arun Gupta

about 4 years ago

Nice blog, Instead of including all the libraries in your classpath, you can also use AppClient which will automatically generate a client with all the dependencies.

Reply

Hull

about 4 years ago

MAN YOUR AWESOME, I HAVE SPENDED A LOT OF HOURS SEARCHING FOR THE MINIMAL JAR LIBS REQUIRED FOR A GFV3 EJB CLIENT. YOU ROCK! Regards from México

Reply

edwin

about 4 years ago

Thanks Hull, glad that it can help. Dont forget to Visit Indonesia, Dangerously Beautiful. :-)

gowtham

about 4 years ago

How to add these jar files to client side's application? actually i donno where they r located on my computer. I'm a newbie.

Reply

edwin

about 4 years ago

hi Gowtham, thanks for asking, you can find these jars on your glassfish installation folder, they are in modules folder. For example, in my PC is, C:\Program Files\glassfish-3.0.1\glassfish\modules.

Gerardo

about 4 years ago

Hello Edwin. Thanks for sharing. I´m also a newbie. I would like to know if you had to install client and server in a production environment, how would you install this program? How would you call the client in a user-friendly way?

Reply

edwin

about 4 years ago

Hi Gerardo, thanks for ur question. Your question is a little bit confusing, but ill try my best to answer it. I like to use exe4j to create an executable application for my client, or you could also try JNLP web start to lauch ur client application from web so you dont have to distribute ur application. Dont forget to include Glassfish libraries on ur client classpath. And how can i call the client in a user-friendly way? Well, i dont know if the server can call the client, try using java.net.Socket or java.net.SocketServer for it.

Fernando

about 4 years ago

java.lang.NoClassDefFoundError: com/sun/enterprise/module/ModulesRegistry ??? why?... I did everything...

Reply

edwin

about 4 years ago

hi fernando, you need to include hk2-core.jar from your glassfish installation lib, well in my PC it's in C:\Program Files\glassfish-3.0.1\glassfish\modules\hk2-core.jar. cheers.

Ron Albury

about 4 years ago

Thanks for helping me get closer. I have a deadline looming and I am !!Desperate!! to get this stand alone client deployed (it runs fine inside Netbeans). I believe I did everything right but I'm getting a null pointer error: SerialContext.(SerialContext.java:198). Do you have any ideas?

Reply

Ron Albury

about 4 years ago

Sorry ... me again. I discovered I had WebStart set in the NetBeans properties. It is all working now.

Reply

edwin

about 4 years ago

hi ron, i'm glad that your program is working well right now, perhaps you could share your complete exception stack trace, and how you managed to fixed it. Maybe it could help others too. Thanks before.

Jeffry

about 4 years ago

Hi Edwin, thanks for your tutorial. I have a question about the client's side application. Why everytime I build the client's side application, the EJB component is undeployed so I have to deploy it again? Thanks man, as a fellow Indonesian I'm proud of you Jeffry

Reply

edwin

about 4 years ago

hi Jeffry, thanks for the question. May i know how you deploy your EJB component, do you use netbeans' to do it or you deploy it manually? Why dont you try to manually deploy your EJB components. First build your project into an EAR application, and then upload it into Glassfish's environment.

Reply

Antonio

about 4 years ago

Hi, Thanks for this tutorial, but I have one question, this client works outside form netbeans? and in another computer? Thanks again

Reply

edwin

about 3 years ago

Hi Antonio, yes this application works well with or without netbeans, and accessible from other computer.

Shamshad Alam

about 3 years ago

@@@@@@@@@@Very very thanks to you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Reply

edwin

about 3 years ago

anytime Shamshad, glad i can help you.

Stefanos

about 3 years ago

Hello edwin, Thanks a lot for the article.. although I had many many issues before I got it (partially) working. --the setup I have setup the server and the client separately, both with maven. I ended up using GF3.0.1 because GF3.1 has a bug with a jar - I don't remember which one now sry.. So the server jar is deployed to GF as an EJB jar. --the problem When I run the client from inside eclipse it works OK. If I package the client to a jar and run it from command line it throws a null pointer exception.. it is thrown in the line `ctx = new InitialContext(props);` $ java -Djava.util.logging.config.file=logging.properties -cp client-1.0-jar-with-dependencies.jar gr.stk.testee.client.ConverterClient 29 - 2011 1:27:19 - com.sun.enterprise.naming.impl.SerialContext FINE: SerialContext ==> SerialContext instance created : SerialContext java.lang.NullPointerException at com.sun.enterprise.naming.impl.SerialContext.(SerialContext.java:198) at com.sun.enterprise.naming.impl.SerialContext.(SerialContext.java:253) Any clues ? thanks in advance!

Reply

edwin

about 3 years ago

hi Stefanos, It's a little bit hard to see what's wrong with your application. Because i cant see both your full exception stacktrace and your source code. My wild guess is, your application couldnt find Glassfish JNDI, so it throws NullPointerException. Do you see this exception? Caused by: javax.naming.NameNotFoundException:

avinash

about 3 years ago

hi edwin, thankx for ur example. i tried this. I am able to get the "CompressedEJBServer" in glassfish admin page under "Applications" tab. when I ran the client,i could get the InitialContext object but my client code hangs while lookup for the bean (at line 29 in the Main.java under CompressedEJBClient, mentioned above). I have done all the configuration but am not able to look up. Also, I am not getting any JNDi external or internal resource on the GF admin console under JNDI tab. Kindly help me for the same.

Reply

edwin

about 3 years ago

Hi Avinash, are you trying to connect from localhost or from other ip? Perhaps your glassfish port is blocked by firewall. Please paste your configuration here, especially your org.omg.CORBA.ORBInitialHost and org.omg.CORBA.ORBInitialPort.

Jack Krauser

about 3 years ago

Can someone help me?

Reply

edwin

about 3 years ago

Hi, Jack Krauser Yes, how may i help you? Could you elaborate your problem more specific, Thank you :)

Anderson

about 3 years ago

Hi Edwin, I am Anderson, from São Paulo, Brazil... I did your tutorial but in console i have this error: java.lang.NoClassDefFoundError: com/sun/corba/ee/spi/folb/GroupInfoServiceObserver... Thanks.......

Reply

edwin

about 3 years ago

Hi Anderson, ithink you need to include glassfish-corba-orb.jar :)

exnesian

about 3 years ago

Hi Edwin... First thanks for your code sample. I need your help, Can you please give me a guide? I have to build, in my newbie state of java, a complex application. It is a java web application that will be run on the glassfish server. the application runs normally waiting for client browser request like common web based application, Say if client by using browser, requests "localhost:8080/webApplication1/index.faces" then the application on the glassfish server executes the code within "index.faces" page and all corresponding MANAGEBEAN CODE inside "index.faces" page. All so far is not really a hard work, but the problem is how to make MANAGEBEAN CODE, that is called earlier, requests some data from another computer, by TCP socket connection like usual client-server app NOT websocket, and then MANAGEBEAN CODE forwards the data to client. and finally as the result the requested data appear on client side. Simply description, there would be an architecture like: Computer A APP on Glassfih ----> Client(Browser) We could say: 1. Client communicates with Computer A INDIRECTLY through APP on Glassfih in purpose requesting some data. 2. Computer A and APP on GlashFish communicate each other in two way communication manner. APP on Glafish applies socket server while Computer A uses client socket. 3. computer-A like can be more than one connecting to APP on Glasfish say Computer A, Computer B.... Computer N! it's like more than one client connecting to server. 4. Client can choose what data form which Computer it will request by adding, for example, parameter in the url like "localhost:8080/webApplication1/index.faces?choice=Computer A" I don't know if I have explained the problem well. From my opinion of a java newbie, it's like combining web App and java socket programming. is it possible? or is there any simple solution? Sorry for addressing you my problem but I really need your help... Beforehand thank you very much! :-)

Reply

edwin

about 3 years ago

Hi exnesian, yes it's very possible. In my latest app, ive connected Struts application ( a simple web app ) to another server using ISO requests ( socket ). basically, the architecure would be like, user -- http request --> glassfish app --- iso / socket request --> another server dont forget, the hard part is how to manage your socket response fast enough, before your http request time out. after all, http request is stateless i know you can do it, afterall you are an extraordinaryindonesian right? ;)

Shahab

about 3 years ago

Hi Edwin. (Subject: Standalone remote java client cannot access EJB3 in Open Source GlassFish3.1.2 running in Eclipse-Helios-OEPE). Any help is appreciated. My simple java client: ---- package org.expense.client; import java.util.Properties; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; import org.expense.stateless.ExpenseBeanRemote; public class ExpenseClient { private void standaloneTest() { try { Properties jndiProps = new Properties(); jndiProps.put("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory"); jndiProps.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming"); jndiProps.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl"); jndiProps.setProperty("org.omg.CORBA.ORBInitialHost", "localhost"); jndiProps.setProperty("org.omg.CORBA.ORBInitialPort", "3700"); Context ctx; ctx = new InitialContext(jndiProps); ExpenseBeanRemote expenseBeanRemote = (ExpenseBeanRemote) ctx.lookup("java:global/Expense/ExpenseEJB/ExpenseBean"); expenseBeanRemote.createItem("0001", "ITEM-1", "I"); System.out.println("Item created...."); } catch (NamingException e) { System.out.println("Expense Client Exception: "+e.getMessage()); e.printStackTrace(); } } public static void main(String[] args) { ExpenseClient expenseClient = new ExpenseClient(); expenseClient.standaloneTest(); } } ---- Proof of JNDI in GlassFish server log: [#|2012-04-16T12:28:36.146-0400|INFO|glassfish3.0.1|javax.enterprise.system.core.transaction.com.sun.jts.CosTransactions|_ThreadID=11;_ThreadName=Thread-1;|JTS5014: Recoverable JTS instance, serverId = [3700]|#] [#|2012-04-16T12:28:36.521-0400|INFO|glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=11;_ThreadName=Thread-1;|Portable JNDI names for EJB ExpenseBean : [java 1="java:global/Expense/ExpenseEJB/ExpenseBean!org.expense.stateless.ExpenseBeanRemote" language=":global/Expense/ExpenseEJB/ExpenseBean,"][/java]|#] [#|2012-04-16T12:28:36.521-0400|INFO|glassfish3.0.1|javax.enterprise.system.container.ejb.com.sun.ejb.containers|_ThreadID=11;_ThreadName=Thread-1;|Glassfish-specific (Non-portable) JNDI names for EJB ExpenseBean : [ejb/ExpenseEjb, ejb/ExpenseEjb#org.expense.stateless.ExpenseBeanRemote]|#] ------------- Exception upon program execution: java.lang.NullPointerException Expense Client Exception: Lookup failed for 'java:global/Expense/ExpenseEJB/ExpenseBean' in SerialContext targetHost=localhost,targetPort=3700 at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297) at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430) at javax.naming.InitialContext.lookup(InitialContext.java:392) at org.expense.client.ExpenseClient.standaloneTest(ExpenseClient.java:35) at org.expense.client.ExpenseClient.main(ExpenseClient.java:49) javax.naming.NamingException: Lookup failed for 'java:global/Expense/ExpenseEJB/ExpenseBean' in SerialContext targetHost=localhost,targetPort=3700 [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=localhost,targetPort=3700 [Root exception is java.lang.NullPointerException]] at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442) at javax.naming.InitialContext.lookup(InitialContext.java:392) at org.expense.client.ExpenseClient.standaloneTest(ExpenseClient.java:35) at org.expense.client.ExpenseClient.main(ExpenseClient.java:49) Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=localhost,targetPort=3700 [Root exception is java.lang.NullPointerException] at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430) ... 3 more Caused by: java.lang.NullPointerException at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297) at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271) ... 4 more -------------- Thanks.

Reply

edwin

about 3 years ago

the main error cause would be Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=localhost,targetPort=3700 [Root exception is java.lang.NullPointerException] at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276) at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430) could you please paste here all the jars you've included in your project, perhaps the main cause of the error is because of missing libraries.

Shahab

about 3 years ago

Thanks Edwin for the clue. I added the missing libraries on the client side; as per your list above in this thread. Also, I had to change my persistence.xml (I'm pasting it for anyone's reference). It worked for me now. By the way, I would appreciate if you have any sample to use "AppClient" from GlassFish to generate client. Thanks again. ------- org.eclipse.persistence.jpa.PersistenceProvider org.expense.jpa.Item org.expense.jpa.ItemExpense <!-- --> -------

edwin

about 3 years ago

Hi Shahab, you could check on my latest writings regarding the appclient feature.

Shahab

about 3 years ago

persistence.xml -------------------- org.eclipse.persistence.jpa.PersistenceProvider org.expense.jpa.Item org.expense.jpa.ItemExpense

Reply

edwin

about 3 years ago

Hi, Shahab sorry, your comment seems not working very well, could you please paste your source to other website such as pastebin, and put the link here. Thank You.

Meziano

about 3 years ago

Hello evrybody, I tried to write almost the same under maven (a maven JEE/EJB-Module and a Java SE Application), unfortunatelly I don't succed to get a connection from the "client". I am frustrated and feel like a blind: I don't know the use of all the jars and which to use. I tried almost anything. Any ideas?? Thank you in advance! Meziano

Reply

edwin

about 3 years ago

Hi Meziano, could you please paste the error stacktrce you've found? Thank You

Meziano

about 2 years ago

Hello edwin, thank you so much for your answer. I am sorry for the delay, I was very busy this week. I tried ta add the libraries or better the dependencies (when working with maven a library is a dependency, isn't it?) I get the following error message: Could not resolve dependencies for project xxx: The following artifacts could not be resolved: org.eclipse.persistence:javax.persistence:jar:2.0.3, org.eclipse.persistence:org.eclipse.persistence.core:jar:2.3.0, org.eclipse.persistence:org.eclipse.persistence.jpa:jar:2.3.0, org.eclipse.persistence:org.eclipse.persistence.jpa.modelgen:jar:2.3.0, org.eclipse.persistence:org.eclipse.persistence.oracle:jar:2.3.0, org.eclipse.persistence:org.eclipse.persistence.antlr:jar:2.3.0, org.eclipse.persistence:org.eclipse.persistence.asm:jar:2.3.0: Failure to find org.eclipse.persistence:javax.persistence:jar:2.0.3 in http://repo.maven.apache.org/maven2 was cached in the local repository, resolution will not be reattempted until the update interval of central has elapsed or updates are forced -> [Help 1] I know that this menas I must provide a valide repository, where the artifacts are available. I could resolve this problem last week and I got another error, I tried to reproduce this, but I had no time. Could you please tell me which dependencies to add and which repositories are valid?? I have another problem: I am working at a JEE project, the GUI is writting by other persons. I cretaed the database, wrote a Java SE application which contains the entities (I let Netbeans generate these from database and fitted them), wrote the testclasses, wrote the ejbs and tested them. I than wrote a stateless webservice in which the other beans are injected. I the webservice, I got the expected result: it's possible to get the list of all instances (rows in the database), get an instance of an instance by ID, update and save it: all CRUD operations are OK. In the Client, a Java SE Application, I added a "web service client" by specifying the WSDL URL. All what I got are detached objects. Every object with its all fields (as strings) EXCEPT THE ID (Primary Key). From an update, I got an insert (cause the edited object has no ID on the client). Remove doesn't work at all. Other operations (findAll, findById) are OK. Do I have to use DTOs (Data Transfer Objects)??? I read that these are not more needed as of ejb3.1 On the clients, for a findAll operation, Netbeans does not accept to use the entities: it forces me to use the autogenerated "dtos", which have the almost the same fileds (except thhe primary key or ID) as the entities but as strings. Do I have misunderstand any thing? It will be great, and I am thankfull in advance if you could help. Meziano

Reply

Januel Yee

about 2 years ago

Hi Edwin, I found your post very helpful and just what we needed on our upcoming project. Unfortunately, while trying to run you example, I encountered these strange error messages: run: C:\Users\Januel\.netbeans\7.0\var\cache\executor-snippets\run.xml:52: java.io.IOException: Cannot run program "C:\Program Files\Java\jdk1.6.0_22\bin\java.exe" (in directory "D:\My Important Misc. Files\Programming Experiments\Java\J2EE and J2SE Crossbreed\CompressedEJBClient"): CreateProcess error=87, The parameter is incorrect at org.apache.tools.ant.taskdefs.Java.fork(Java.java:798) at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:214) at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:135) at org.apache.tools.ant.taskdefs.Java.execute(Java.java:108) at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:291) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:106) at org.apache.tools.ant.Task.perform(Task.java:348) at org.apache.tools.ant.Target.execute(Target.java:390) at org.apache.tools.ant.Target.performTasks(Target.java:411) at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1399) at org.apache.tools.ant.Project.executeTarget(Project.java:1368) at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41) at org.apache.tools.ant.Project.executeTargets(Project.java:1251) at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:284) at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:539) at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:153) Caused by: java.io.IOException: Cannot run program "C:\Program Files\Java\jdk1.6.0_22\bin\java.exe" (in directory "D:\My Important Misc. Files\Programming Experiments\Java\J2EE and J2SE Crossbreed\CompressedEJBClient"): CreateProcess error=87, The parameter is incorrect at java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at java.lang.Runtime.exec(Runtime.java:593) at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:862) at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:481) at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:495) at org.apache.tools.ant.taskdefs.Java.fork(Java.java:791) ... 19 more Caused by: java.io.IOException: CreateProcess error=87, The parameter is incorrect at java.lang.ProcessImpl.create(Native Method) at java.lang.ProcessImpl.(ProcessImpl.java:81) at java.lang.ProcessImpl.start(ProcessImpl.java:30) at java.lang.ProcessBuilder.start(ProcessBuilder.java:453) ... 24 more Java Result: -1 I will be looking for some answers online too. Hopefully, you can help me with this error messages. Your example is a very good concept! Your help and advice will be very much appreciated. Regards, Januel Yee

Reply

edwin

about 2 years ago

Hi Januel, it happen because your classpath is too long, try shorten it or remove some unnecessary libraries. Here is a short description regarding your error. http://stackoverflow.com/questions/2893970/fail-to-launch-application-createprocess-error-87-cant-use-shorten-classpath

Vena

about 2 years ago

Dear edwin, we are trying to get this working on the lan but still getting the ComponentException: injection failed on com.sun.enterprise.iiop.security.IIOPSSLUtilImpl.sslUtils Exception. Is there any possibility to get this work on a lan. We have security turned off but still getting this message, thank you very much

Reply

edwin

about 2 years ago

Hi Vena, looks like it has some issue with the SSL problem. I havent met that kind of error yet, so i cant give any suggestion. Sorry :(

Bharat

about 2 years ago

Hello edwin can u give me source code for the same please. Thanks in advanced.

Reply

edwin

about 2 years ago

Hi Bharat, you could see all the sourcecode on this page :)

BHarat

about 2 years ago

May 21, 2012 2:59:36 PM com.sun.enterprise.v3.server.CommonClassLoaderServiceImpl findDerbyClient INFO: Cannot find javadb client jar file, derby jdbc driver will not be available by default. log4j:WARN No appenders could be found for logger (com.edw.main.Main). log4j:WARN Please initialize the log4j system properly.

Reply

Vena

about 2 years ago

Dear Edwin, please can you help me? I use similar thing and everything works fine in Netbeans but when I create the jar from client, I get an ClassNotFoundException: com.sun.corba.ee.spi.folb.GroupInfoserviceObserver, can you suggest what could be wrong, thank you very much.

Reply

Vena

about 2 years ago

Oh and I have glassfish.corba.org imported in my project. Thanks

edwin

about 2 years ago

Hi Vena, it seems that you havent include glassfish jar libraries in your jar's classpath.

Anirban

about 2 years ago

Hi Edwin, good post thanks. I utilized your initial context lookups in my post here: http://anirbanchowdhury.wordpress.com/2012/06/07/ejb-3-application-in-glassfish-3x/ Instead of using all client libs, why dont you just reference gf-client.jar from GF installation location? Saves a lot of duplication.

Reply

edwin

about 2 years ago

Hi Anirban, thank you for your comment. Im including all the jars from glassfish because im planning on moving the client's application to computers which doesnt have any glassfish installation.

Gnuce Lee

about 2 years ago

Hi Edwin, thank you for your post. I have tried your method and it works if I connect to GF on localhost. As soon as I try to connect to remote GF, exception is thrown when calling ctx.lookup. WARNING: IOP00410019: Communications timeout waiting for response. Exceeded 1,800,000 milliseconds org.omg.CORBA.COMM_FAILURE: WARNING: IOP00410019: Communications timeout waiting for response. Exceeded 1,800,000 milliseconds vmcid: OMG minor code: 19 completed: Maybe Remote server is in local network, ORB listener is bound to 0.0.0.0 and is listening on port 3700, I also can telnet to that port.

Reply

edwin

about 2 years ago

Hi Gnuce Lee, Communication timeout happen because it takes too long for client side's ejb to find the server's side. have you try to ping -t the target server and see whether there is Read Time Out errors, or try changing the target port? Or using packet sniffer software perhaps, like wireshark or tcpviewer? :)

MCKei

about 2 years ago

Hi Edwin, thanks for your helpful post But I have a problem. When I create new session bean, I can't choose the Remote Interface, It said: "There is no suitable project available into which Remote Interface could be" :( If I skip this by uncheck anything, I can not add the EJB module project to java application project. It said "can't add cyclic references". And if I create the EJB module after create java application, I can choose Remote Interface but the java package appear in java application project, not in EJB module project like your. Please, help!

Reply

edwin

about 2 years ago

Hi MCKei, try creating an ejb project first, and then include your ejb project into your other java project. It supposed not too hard :D

Sudhir Dhumal

about 2 years ago

Hi Edwin... The solution you provided is helpful for me. It is working nicely in eclipse IDE when added project containing business interface in classpath. but when i tried to run the application from command line got an exception. ---------- Added all the jar files (using eclipse extraction functionality) in single jar. ---------- -------Stack Trace------- java.lang.NullPointerException at com.sun.enterprise.naming.impl.SerialContext.(SerialContext.java:275) at com.sun.enterprise.naming.impl.SerialContext.(SerialContext.java:334) at com.sun.enterprise.naming.impl.SerialInitContextFactory.createInitialContext(SerialInitContextFactory.java:358) at com.sun.enterprise.naming.impl.SerialInitContextFactory.getInitialContext(SerialInitContextFactory.java:353) at com.sun.enterprise.naming.SerialInitContextFactory.getInitialContext(SerialInitContextFactory.java:69) at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:684) at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:307) at javax.naming.InitialContext.init(InitialContext.java:242) at javax.naming.InitialContext.(InitialContext.java:216) at ejb.desktopclient.FetchEJBMessage.main(FetchEJBMessage.java:26)

Reply

edwin

about 2 years ago

Hi Sudhir Dhumal, i think it because you missed some libraries when you export it into a single jar, please share your complete exception stacktrace.

rahul

about 2 years ago

Hi Edwin, I've included the all jars in my client , then I got the following exception java.lang.ClassCastException: javax.naming.Reference cannot be cast to javax.sql.DataSource

edwin

about 2 years ago

Hi Rahul, I think it happen because of you are casting javax.naming.Reference to javax.sql.DataSource. Could you please share your complete sourcecode?

rajneekanth

about 2 years ago

hi edwin, I followed your post and created a client/server application. but when I run I am getting this error. Lookup failed for 'com.jm.facade.ConnectionFacadeRemote' in SerialContext[myEnv={org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory, org.omg.CORBA.ORBInitialHost=localhost, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl} so, I have added all the jars from the modules directory, but still I am getting all these errors. can you help me.

Reply

edwin

about 2 years ago

Hi rajneekanth, it happens because your client ejb could find your server ejb perhaps it's because of missconfiguration or your glassfish app is not running yet.

mauro

about 2 years ago

escuse me but if i would connect to a ejb that it is behind a router , how i can to get the app client to work? the orb communicate always on ip private adress af LAN and not for external IP publi adress.

Reply

edwin

about 2 years ago

Hi Mauro, try to portforwarding your router to your server's private ip. So whenever your client app hit your router's port, your router would directly moved those requests to your server's local ip.

mauro

about 1 year ago

yes i have make it but it not work I have ubuntu 10.04 with glassfsih remote installed

Reply

edwin

about 1 year ago

Can you telnet to the target server's port? Or is it possible you have firewall blocked your ports on your Ubuntu?

msama

about 1 year ago

Hello edwin, i am still bigginer in ejb, and i am face a confusing to understand deplying ejb session bean project. I am using Eclipse(java EE) and glassfish server 3.1.2, i need to use i web application to deal with my ejb session bean. so, can you help me to get started with this point.

Reply

edwin

about 1 year ago

Hi msama, you can start by trying to connect your web application to your local ejb, using a simple @EJB annotation.

msama

about 1 year ago

It's OK, I tried and it worked fine. And then what is the next step?

edwin

about 1 year ago

well how about trying to connect to database from your ejb service :)

msama

about 1 year ago

OK. Till now I build a complete application to connect to oracle database using stateless session bean on glassfish server 4 and using JPA to connect database. Everything going fine except one thing that when I try to insert Arabic data using jsp and servlets to DB, it became like this '?????' but when i insert them directly from the application, it's working fine. I tried to change the encoding but same result. Your advice please and hope don't late.

edwin

about 1 year ago

hi msama, try adding UTF8 CharacterEncoding to your request, or just create a simple servletfilter to do so, [code] request.setCharacterEncoding("UTF-8"); [/code] while on your jsp, create [code] <%@ page pageEncoding="UTF-8" %> [/code] on top of your jsp file.

msama

about 1 year ago

I tried all this and finally the iso-8859-1 worked fine with some converting and I could insert arabic data correctly to DB. now i found problem, it's the opposite which I can't show arabic data on the page while the encoding is iso-8859-1.

MrHieu17

about 1 year ago

Hi, i tried this. when run by Netbean, it's OK; but when i use CMD command, it got exception: C:\Users\mrhie_000\Desktop\Client\dist>java -jar Client.jar Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/corba/ee/spi/ folb/GroupInfoServiceObserver at com.sun.enterprise.naming.SerialInitContextFactory.(SerialInitC ontextFactory.java:62) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou rce) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.init(Unknown Source) at javax.naming.InitialContext.(Unknown Source) at com.edw.main.Main.connect(Main.java:26) at com.edw.main.Main.main(Main.java:37) Caused by: java.lang.ClassNotFoundException: com.sun.corba.ee.spi.folb.GroupInfo ServiceObserver at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 13 more Can you help me!!! sr for my english is not good...

Reply

MrHieu17

about 1 year ago

@@ Wow i update glassfish 4+ @@ it become better but still have an exception @@ help me pls Exception in thread "main" java.lang.NoSuchMethodError: com.sun.enterprise.modul e.ModulesRegistry.createServiceLocator(Ljava/lang/String;)Lorg/glassfish/hk2/api /ServiceLocator; at org.glassfish.internal.api.Globals.getStaticHabitat(Globals.java:102) at com.sun.enterprise.naming.impl.SerialInitContextFactory.(Serial InitContextFactory.java:130) at com.sun.enterprise.naming.SerialInitContextFactory.(SerialInitC ontextFactory.java:62) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou rce) at java.lang.reflect.Constructor.newInstance(Unknown Source) at java.lang.Class.newInstance0(Unknown Source) at java.lang.Class.newInstance(Unknown Source) at javax.naming.spi.NamingManager.getInitialContext(Unknown Source) at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source) at javax.naming.InitialContext.init(Unknown Source) at javax.naming.InitialContext.(Unknown Source) at com.edw.main.Main.connect(Main.java:26) at com.edw.main.Main.main(Main.java:37)

edwin

about 1 year ago

Hi MrHieu17, it happened because there is incompatibility between your classpath libraries and glassfish's libraries, try to revert back to gf 3.1 instead.

edwin

about 1 year ago

Hi MrHieu17, i think you need to include glassfish-corba-internal-api.jar into your classpath :)

Leave a Comment

Please be polite. We appreciate that.
Your email address will not be published and required fields are marked


:-[ (B) (^) (P) (@) (O) (D) :-S ;-( (C) (&) :-$ (E) (~) (K) (I) (L) (8) :-O (T) (G) (F) :-( (H) :-) (*) :-D (N) (Y) :-P (U) (W) ;-)