Search code examples
glassfishjava-ee-7

commandline tool Glassfish appclient doesn't see deployed EJB


I'm working my way through a book about "Java EE 7 for Glassfish", with the server installed on Fedora Linux.

I have a simple stateless session bean SimpleSessionBean deployed on the server and I am trying to approach that SimpleSessionBean via SessionBeanClient and the Glassfish command line tool appclient, running a client jar. Everything from the book, so it should work. The client however can't find SimpleSessionBean. Apparently a class path issue. In the server logs nothing happened.

I can't find any pointers how Glassfish should be properly installed. Everything works within the server. I can approach installed war files from facelets running in a browser.

It is probably a matter of setting $PATH right or something or some other environment variable. Any pointers to relevant literature?

Thanks in advance for any suggestions!

UPDATE1: error message

From the bash terminal window where I run appclient:

[fedora@localhost bin]$ ./appclient -client /home/fedora/Downloads/6886EN_04_Code/ch04_src/simplesessionbeanclient/target/simplesessionbeanclient.jar

Jul 06, 2017 12:52:57 PM org.glassfish.apf.impl.DefaultErrorHandler error SEVERE: Class [ Lnet/ensode/glassfishbook/SimpleSession; ] not found.

Error while loading [ class net.ensode.glassfishbook.SessionBeanClient ] Exception in thread "main" java.lang.NoClassDefFoundError: net/ensode/glassfishbook/SimpleSession at net.ensode.glassfishbook.SessionBeanClient.invokeSessionBeanMethods(SessionBeanClient.java:12) at net.ensode.glassfishbook.SessionBeanClient.main(SessionBeanClient.java:19) Caused by: java.lang.ClassNotFoundException: net.ensode.glassfishbook.SimpleSession at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at org.glassfish.appclient.client.acc.ACCClassLoader.findClass(ACCClassLoader.java:237) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at java.lang.ClassLoader.loadClass(ClassLoader.java:357)

UPDATE2: From the Glassfish book:

We are using Maven to build our code. For this example, we used the Maven Assembly plugin (http://maven.apache.org/plugins/maven-assembly-plugin/) to build a client JAR file that includes all dependencies; this frees us from having to specify all the dependent JAR files in the -classpath command-line option of the appclient utility. To build this JAR file, simply invoke mvn assembly:assembly from the command line.

SOLUTION: the missing link was producing a client jar with additional jar's "on board" so to speak. Proceed as follows (at least in Eclipse): select pom.xml > right-click > Run As > Maven build... > enter in Goals field: assembly:assembly> Apply/Run.

The result will be that you will find TWO jars under your target folder: xxxclient.jar and xxxclient-jar-with-dependencies.jar. From the command line in bash execute from the folder with latter jar:

/path_to/appclient -client xxxclient-jar-with-dependencies.jar

After a very long wait (on my $200 mini Linux box) the HelloWorld-ish server EJB gets finally properly called.


Solution

  • Your assumption is right.

    You are missing net.ensode.glassfishbook.SimpleSession in your classpath.

    From an older book online:

    ...executed through the appclient utility. This utility can be found at [glassfish installation directory]/glassfish/bin/. Assuming this path is in the PATH environment variable, and assuming we placed our client code in a JAR file called simplesessionbeanclient.jar, we would execute the above client code by typing the following command in the command line:

    appclient -client simplesessionbeanclient.jar

    It seems that you've started from

    .../bin/./appclient -client /home/fedora/Downloads/6886EN_04_Code/ch04_src/simplesessionbeanclient/target/simplesessionbeanclient.jar

    You need SimpleSession.class in your CLASSPATH (or in a jar in that classpath). Usually java checks the current directory first (which is your bin folder). If the class is not found (its not, since its in your simplesessionbeanclient folder), it searches for that class in the classpath (where you did not add the simplesessionbeanclient folder).

    Try

    appclient -client simplesessionbeanclient.jar
    

    from the folder where simplesessionbeanclient.jar is located. If you don't want to add the appclient folder to your path start with

    /your/path/to/appclient -client simplesessionbeanclient.jar
    

    (again from the folder where simplesessionbeanclient.jar is located)

    Update: If you still get a ClassNotFoundException have a look if it is missing in your jar file (jars are Zip-File, you could use your Zip-Tools):

    jar tf simplesessionbeanclient.jar
    

    if there is a SimpleSession.class