Issue
When GreeterEJB
builds as a JAR, it doesn't build with a libs folder for dependencies:
thufir@doge:~$
thufir@doge:~$ ll NetBeansProjects/GreeterEJB/dist/
total 20
drwxrwxr-x 2 thufir thufir 4096 Feb 25 14:34 ./
drwxrwxr-x 6 thufir thufir 4096 Feb 25 14:34 ../
-rw-rw-r-- 1 thufir thufir 2802 Feb 25 14:34 GreeterEJB.jar
thufir@doge:~$
However, when it deploys, Glassfish gives the following error:
Error in annotation processing: {0}.
java.lang.NoClassDefFoundError: net/bounceme/doge/greeter/ejb/GreeterRemote
because, I think, it can't find the GreeterRemote
class, as that class is in a different JAR:
thufir@doge:~$
thufir@doge:~$ jar -tf NetBeansProjects/GreeterLibrary/dist/GreeterLibrary.jar | grep class
net/bounceme/doge/greeter/ejb/GreeterRemote.class
thufir@doge:~$
What's the nature of this dependency? How is this different from adding a class to the classpath of project? At least in Netbeans, when, for example, a JDBC driver is added to the classpath, that driver will show up in the libs folder alongside the JAR which was built.
the ejb:
package net.bounceme.doge.greeter.ejb;
import javax.ejb.Stateless;
@Stateless
public class GreeterBean implements GreeterRemote {
@Override
public String greeting() {
return "hello remote world";
}
}
greeter remote interface:
package net.bounceme.doge.greeter.ejb;
import javax.ejb.Remote;
@Remote
public interface GreeterRemote {
String greeting();
}
The GreeterLibrary JAR file added to glassfish:
thufir@doge:~$
thufir@doge:~$ ll glassfish-4.1/glassfish/lib/*.jar
-rw-r--r-- 1 thufir thufir 2694 Feb 22 18:56 glassfish-4.1/glassfish/lib/appserv-rt.jar
-rw-rw-r-- 1 thufir thufir 20020 Feb 25 06:06 glassfish-4.1/glassfish/lib/EJBRemoteInterface.jar
-rw-r--r-- 1 thufir thufir 22189 Feb 22 18:56 glassfish-4.1/glassfish/lib/gf-client.jar
-rw-r--r-- 1 thufir thufir 3193 Feb 22 18:56 glassfish-4.1/glassfish/lib/javaee.jar
-rw-r--r-- 1 thufir thufir 1398 Feb 22 18:56 glassfish-4.1/glassfish/lib/jndi-properties.jar
-rw-r--r-- 1 thufir thufir 1006015 Feb 23 16:58 glassfish-4.1/glassfish/lib/mysql-connector-java.jar
thufir@doge:~$
thufir@doge:~$ ll glassfish-4.1/glassfish/domains/domain1/lib/*.jar
-rw-rw-r-- 1 thufir thufir 20020 Feb 25 06:06 glassfish-4.1/glassfish/domains/domain1/lib/EJBRemoteInterface.jar
thufir@doge:~$
thufir@doge:~$ ll glassfish-4.1/glassfish/domains/domain1/lib/classes/*.jar
-rw-rw-r-- 1 thufir thufir 20020 Feb 25 06:06 glassfish-4.1/glassfish/domains/domain1/lib/classes/EJBRemoteInterface.jar
thufir@doge:~$
I recall doing something like this before with remote interfaces, but I seem to have forgotten a key step with the remote interface, and, at the moment, cannot find the right Google terms. I'm sure somewhere in the Glassfish manual there's a section on EJB dependencies and where they go...
Right now, I just want to know the nature or type of dependency this is so that I at least know what to Google for.
Solution
You don't want to place the dependencies you developed on your own inside the Glassfish lib folder. This may be sufficient for productive usage, but not for development.
To do it right, you need an EAR.
Inside the EAR, you can create a lib
folder for your dependencies.
The EAR structure will look similar to this:
/EAR
/EAR/GreeterEJB.jar
/EAR/lib
/EAR/lib/GreeterLibrary.jar
Answered By - unwichtich
Answer Checked By - Timothy Miller (JavaFixing Admin)