users@glassfish.java.net

Re: Standalone client of GlassFish v3

From: <glassfish_at_javadesktop.org>
Date: Wed, 10 Mar 2010 00:26:01 PST

Hi,

The "java -jar HelloApp-std-client.jar" command is correct because the MANIFEST.MF contains the Class-Path.

One library that I made for the standalone mode and called it "SunGFv3" is contained these jars:
  acc-config.jar
  gf-client.jar
  gf-client-module.jar
  gf-connectors-connector.jar
  gf-ejb-connector.jar
  gf-jruby-connector.jar
  gf-web-connector.jar

Here is the code, environment and the result what you ask from me.

Attila.

COMMON CODE
-------------------------
package enterprise.hello_stateless_ejb;

import javax.ejb.Remote;

@Remote
public interface StatelessSession {

    public String hello();

}

SERVER CODE
------------------------
package enterprise.hello_stateless_ejb;

import javax.ejb.Stateless;

@Stateless
public class StatelessSessionBean implements StatelessSession {

    public String hello() {
        return "hello, world!\n";
    }

}

APPLICATION CLIENT CODE
--------------------------------------------
package enterprise.hello_stateless_client;

import javax.ejb.EJB;
import enterprise.hello_stateless_ejb.StatelessSession;

public class StatelessJavaClient {

    @EJB
    private static StatelessSession sless;

    public static void main(String args[]) {
        System.out.println("StatelessSession bean says : " + returnMessage());
    }

    public static String returnMessage() {

        try {
            return (sless.hello());

        } catch(Exception e) {
            e.printStackTrace();
        }

        return null;
    }

}


STANDALONE CLIENT CODE
---------------------------------------------
package enterprise.hello_stateless_client;

import javax.naming.InitialContext;
import enterprise.hello_stateless_ejb.StatelessSession;

public class StandaloneStatelessJavaClient {

    public static void main(String args[]) {
        System.out.println("StatelessSession bean says : " + returnMessage());
    }

    public static String returnMessage() {

        try {
            InitialContext ic = new InitialContext();
            StatelessSession sless = (StatelessSession)
                ic.lookup("enterprise.hello_stateless_ejb.StatelessSession");
                //ic.lookup("java:global/HelloApp/HelloApp-ejb/StatelessSessionBean");
            return (sless.hello());

        } catch(Exception e) {
            e.printStackTrace();
        }

        return null;
    }

}

0, My Ubuntu 9.10 (64bit)'s environment is
--------------------------------------------------------------
ANT_HOME=/java/netbeans-6.8/java3/ant
ANT_PATH=/java/netbeans-6.8/java3/ant/bin
BASH=/bin/bash
BASH_ALIASES=()
BASH_ARGC=()
BASH_ARGV=()
BASH_CMDS=()
BASH_LINENO=()
BASH_SOURCE=()
BASH_VERSINFO=([0]="4" [1]="0" [2]="33" [3]="1" [4]="release" [5]="x86_64-pc-linux-gnu")
BASH_VERSION='4.0.33(1)-release'
CLASSPATH=/java/jdk1.6.0_18/jre/lib:/java/jdk1.6.0_18/lib:.:./lib:./ext
COLORTERM=gnome-terminal
COLUMNS=158
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-P6TtNgDYMt,guid=6cd657eab1badc652005b6324b960e0c
DESKTOP_SESSION=gnome
DIRSTACK=()
DISPLAY=:0.0
EUID=0
GDK_NATIVE_WINDOW=1
GDMSESSION=gnome
GDM_KEYBOARD_LAYOUT=$'us\tintl'
GDM_LANG=hu_HU.UTF-8
GF_HOME=/java/sges-v3/glassfish
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
GNOME_KEYRING_PID=1954
GNOME_KEYRING_SOCKET=/tmp/keyring-mMj1zn/socket
GPG_AGENT_INFO=/tmp/seahorse-m8ocUh/S.gpg-agent:2037:1
GROUPS=()
GTK_MODULES=canberra-gtk-module
GTK_RC_FILES=/etc/gtk/gtkrc:/root/.gtkrc-1.2-gnome2
HISTCONTROL=ignorespace
HISTFILE=/root/.bash_history
HISTFILESIZE=500
HISTSIZE=500
HOME=/root
HOSTNAME=aszomor
HOSTTYPE=x86_64
IFS=$' \t\n'
JAVA_HOME=/java/jdk1.6.0_18
JAVA_PATH=/java/jdk1.6.0_18/bin
LANG=hu_HU.UTF-8
LESSCLOSE='/usr/bin/lesspipe %s %s'
LESSOPEN='| /usr/bin/lesspipe %s'
LINES=43
LOGNAME=root
LS_COLORS='rs=0:di=01;34:ln=01;36:hl=44;37:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:'
MACHTYPE=x86_64-pc-linux-gnu
MAILCHECK=60
MC_SID=4428
MC_TMPDIR=/tmp/mc-root
OLDPWD=/
OPTERR=1
OPTIND=1
ORBIT_SOCKETDIR=/tmp/orbit-root
OSTYPE=linux-gnu
PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/java/jdk1.6.0_18/bin:/java/netbeans-6.8/java3/ant/bin:~/bin'
PIPESTATUS=([0]="0")
PLUGIN_HOME=/java/jre1.6.0_18/plugin
PPID=4426


1, Deploy HelloApp into GlassFish v3 Domain1
--------------------------------------------------------------------
INFO: Security startup service called
INFO: SEC1143: Loading policy provider com.sun.enterprise.security.provider.PolicyWrapper.
INFO: Realm admin-realm of classtype com.sun.enterprise.security.auth.realm.file.FileRealm successfully created.
INFO: Realm file of classtype com.sun.enterprise.security.auth.realm.file.FileRealm successfully created.
INFO: Realm certificate of classtype com.sun.enterprise.security.auth.realm.certificate.CertificateRealm successfully created.
INFO: Security service(s) started successfully....
INFO: JTS5014: Recoverable JTS instance, serverId = [3700]
INFO: Portable JNDI names for EJB StatelessSessionBean : [java:global/HelloApp/HelloApp-ejb/StatelessSessionBean!enterprise.hello_stateless_ejb.StatelessSession, java:global/HelloApp/HelloApp-ejb/StatelessSessionBean]
INFO: Glassfish-specific (Non-portable) JNDI names for EJB StatelessSessionBean : [enterprise.hello_stateless_ejb.StatelessSession, enterprise.hello_stateless_ejb.StatelessSession#enterprise.hello_stateless_ejb.StatelessSession]
INFO: WELD-000900 1.0.0 (SP4)
INFO: Instantiated an instance of org.hibernate.validator.engine.resolver.JPATraversableResolver.
INFO: nullID: /java/projects-6.8/HelloApp/dist/gfdeploy/HelloApp/HelloApp-app-client_jar/ CLASSES: [class enterprise.hello_stateless_client.StatelessJavaClient]
   ID: /java/projects-6.8/HelloApp/dist/gfdeploy/HelloApp/HelloApp-app-clemb_jar/ CLASSES: [interface enterprise.hello_stateless_ejb.StatelessSession, class enterprise.hello_stateless_client.EmbStatelessJavaClient] ID: /java/projects-6.8/HelloApp/dist/gfdeploy/HelloApp/HelloApp-ejb_jar/ CLASSES: [class enterprise.hello_stateless_ejb.StatelessSessionBean]ID: /java/projects-6.8/HelloApp/dist/gfdeploy/HelloApp/HelloApp-app-clemb_jar/ CLASSES: [interface enterprise.hello_stateless_ejb.StatelessSession, class enterprise.hello_stateless_client.EmbStatelessJavaClient]
   ID: /java/projects-6.8/HelloApp/dist/gfdeploy/HelloApp/HelloApp-app-client_jar/ CLASSES: [class enterprise.hello_stateless_client.StatelessJavaClient] ID: /java/projects-6.8/HelloApp/dist/gfdeploy/HelloApp/HelloApp-ejb_jar/ CLASSES: [class enterprise.hello_stateless_ejb.StatelessSessionBean]ID: /java/projects-6.8/HelloApp/dist/gfdeploy/HelloApp/HelloApp-ejb_jar/ CLASSES: [class enterprise.hello_stateless_ejb.StatelessSessionBean]
   ID: /java/projects-6.8/HelloApp/dist/gfdeploy/HelloApp/HelloApp-app-client_jar/ CLASSES: [class enterprise.hello_stateless_client.StatelessJavaClient] ID: /java/projects-6.8/HelloApp/dist/gfdeploy/HelloApp/HelloApp-app-clemb_jar/ CLASSES: [interface enterprise.hello_stateless_ejb.StatelessSession, class enterprise.hello_stateless_client.EmbStatelessJavaClient]
INFO: ACDEPL103: Java Web Start services started for the app client HelloApp/HelloApp-app-clemb.jar (contextRoot: /HelloApp/HelloApp-app-clemb)
INFO: ACDEPL103: Java Web Start services started for the app client HelloApp/HelloApp-app-client.jar (contextRoot: /HelloApp/HelloApp-app-client)
INFO: HelloApp was successfully deployed in 9 892 milliseconds.

2, Generate stub for HelloAppClient
---------------------------------------------------
/java/sges-v3/glassfish/bin/asadmin get-client-stubs --appname HelloApp /java/projects/HelloApp/dist
THE RESULT IS:
--------------------------
Authentication failed with password from login store: /root/.asadminpass
Enter admin password for user "admin">

Command get-client-stubs executed successfully.

3, Start HelloAppClient
---------------------------------
cd /java/projects/HelloApp/dist
/java/sges-v3/glassfish/bin/appclient -client HelloAppClient.jar -name HelloApp-app-client
THE RESULT IS:
-------------------------
2010.03.10. 8:45:28 com.sun.enterprise.transaction.JavaEETransactionManagerSimplified initDelegates
INFO: Using com.sun.enterprise.transaction.jts.JavaEETransactionManagerJTSDelegate as the delegate
StatelessSession bean says : hello, world!

4a, HelloApp Standalone Client environment
-----------------------------------------------------------------
/java/projects/HelloApp/HelloApp-std-client/dist/lib
  acc-config.jar
  gf-client.jar
  gf-client-module.jar
  gf-connectors-connector.jar
  gf-ejb-connector.jar
  gf-jruby-connector.jar
  gf-web-connector.jar
  HelloApp-com.jar
  javaee-api-6.0.jar
/java/projects/HelloApp/HelloApp-std-client/dist
  HelloApp-std-client.jar

4b, The MANIFEST.MF in HelloApp-std-client.jar
-----------------------------------------------------------------------
Manifest-Version: 1.0
Ant-Version: Apache Ant 1.7.1
Created-By: 16.0-b13 (Sun Microsystems Inc.)
Main-Class: enterprise.hello_stateless_client.StandaloneStatelessJavaC
 lient
Class-Path: lib/javaee-api-6.0.jar lib/acc-config.jar lib/gf-client-mo
 dule.jar lib/gf-client.jar lib/gf-connectors-connector.jar lib/gf-ejb
 -connector.jar lib/gf-jruby-connector.jar lib/gf-web-connector.jar li
 b/HelloApp-com.jar

4c, Start HelloApp Standalone Client
-----------------------------------------------------
cd /java/projects/HelloApp/HelloApp-std-client/dist
java -jar HelloApp-std-client.jar
THE RESULT IS:
-------------------------
javax.naming.NoInitialContextException: Cannot instantiate class: com.sun.enterprise.naming.SerialInitContextFactory [Root exception is java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory]
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:657)
        at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:288)
        at javax.naming.InitialContext.init(InitialContext.java:223)
        at javax.naming.InitialContext.<init>(InitialContext.java:175)
        at enterprise.hello_stateless_client.StandaloneStatelessJavaClient.returnMessage(StandaloneStatelessJavaClient.java:50)
        at enterprise.hello_stateless_client.StandaloneStatelessJavaClient.main(StandaloneStatelessJavaClient.java:44)
Caused by: java.lang.ClassNotFoundException: com.sun.enterprise.naming.SerialInitContextFactory
        at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:247)
        at com.sun.naming.internal.VersionHelper12.loadClass(VersionHelper12.java:46)
        at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:654)
        ... 5 more
StatelessSession bean says : null
[Message sent by forum member 'aszomor' (attila_at_szomor.hu)]

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