users@glassfish.java.net

Re: EJB Client runs in Netbeans, but not outside

From: <glassfish_at_javadesktop.org>
Date: Thu, 15 Jul 2010 09:16:18 PDT

I have done it! The secret is to use appclient (that brings the proper environment) instead of just java. It didn't use to work, but it was only a Glassfish V3.0 bug (fixed in V3.01). The steps to make it working:

1. Upgrade to Glassfish V3.01
-------------------------------------------
NetBeans 6.8 currently installs Glassfish V3.0 (with the problem). Either:
-- Use updatetool (in the "bin" of the Glassfish installation directory) to upgrade to V3.01 (it didn't work for me as I forgot to execute it as administrator on Vista)
    or
-- Install NetBeans 6.9 that comes with Glassfish V3.01

I actually used a third solution: I downloaded Java EE 6 SDK (including Glassfish but without NetBeans) from http://java.sun.com/javaee/downloads/index.jsp, installed it, then declared the server in my NetBeans 6.8 as a new Glassfish v3 kind server (under a new name: "Glassfish V3.1)

2. Write and build the code
---------------------------------------
I created a new JEE application including an EJB module and a simple client module (not a Web one). In the properties of the application I manually specified the Main class of the simple client module to be ran.

Actually I had already did this before for the Glassfish V3 domain server (and it worked from NetBeans but not outside). So all I had to do was to go to the properties of the application plus each of the module to specify the new server as target. (Usually you cannot change the server afterwards, but as it is of the "Glassfish v3" kind too, you can do it.)

Then I Clean and Build everything and Deploy. I also Run from NetBeans to test.

When doing this, NetBeans creates a directory"MyAppClient" (if the project is called "MyApp") and several .jar files (refering to each other through their MANIFEST files). The miminum necessary files are:
-- MyAppClient/MyApp-app-client.jar
-- MyApp-ejb.jar

3. Run the client as a standalone client
--------------------------------------------------------
I copied the two files in a separate directory ./newdir.

I added the "bin" of the Glassfish V3.01 installation directory to the PATH (so to have the "appclient" or "appclient.bat" file in the PATH).

Then I ran the application as:
    appclient -client newdir/MyApp-app-client.jar

AND IT WORKED! (With Glassfish V3.0 all I got was "NullPointer Exception").

The "appclient" tool is described here:
http://docs.sun.com/app/docs/doc/820-7701/appclient-1m?l=en&a=view&q=appclient
and it brings all the necessary libraries.

Some observations
---------------------------
It seems (it obviously should, but I didn't try yet) to be possible to run appclient on a remote client machine in order to connect to a server over the network (by specifying the proper connection parameters in the proper XML files). This implies that the appclient is installed on any remote client computer. That implies that Glassfish is installed on every remote client computer?

It seems (I found on a forum - I don't remember where) that the ".jar" files must be build for each of the client platforms, as the Glassfish platform specific distribution includes same platform-native libraries in them.

The tool "appclient" allows to properly specify a user name and password in order to be able to call protected EJBs on the server.
[Message sent by forum member 'mdynca']

http://forums.java.net/jive/thread.jspa?messageID=477743