Sounds fairly straightforward right?
I also thought so initially. Unfortunately there are a couple nasty and not so little bumps that turn this from a trip to shops to neigh on the Roof of Africa Rally!
First step is easy, let’s use the bundled GlassFish App Server..
And there goes a frustrating couple of hours / days / weeks of your life, Let me explain.
GlassFish has a client jar ($GLASSFISH_HOME/modules/gf-client.jar) that you are supposed to include with your application to connect to the EJB backend. This all works fine when you are testing with your public static void main tests, however there are a couple of things to note that you will not be immediately apparent on your development machine.
- gf-client.jar is just a meta-jar, all that it does is reference other jars, which in turn can reference other jars ad infinitum.
- The moment you take your test application off your computer it will fail. In all likelihood you have included gf-client.jar, but you haven’t included all of its references. What this means is that you have got to install GlassFish App Server on all of the computers that you want to install your software on, or figure out what the dependency tree is (I’ll save you some time, it’s pretty much the same as installing, You get about every single jar that is included in the full install)
- After you’ve figured all of this out, your Netbeans application still will not run. Why? Read here and here to understand the problem.
Right let’s get this show back on the road. What are we going to need in order to get this to work?
- NetBeans
- Maven
- JBoss
- Patience
Setting up the JBoss Client Libraries
First off what you need to do is find all of the JBoss Client Dependencies and create a Maven artifact from them. Thankfully I didn’t need to do that, somebody had already figured it out for me.
Here’s the pom file
4.0.0 sparg.tim JBossClientLibraries jar 5.10 JBossClientLibraries http://maven.apache.org org.jboss.javaee jboss-javaee 5.0.1.GA org.hibernate hibernate-annotations 3.4.0.GA org.hibernate hibernate-commons-annotations org.hibernate hibernate-core dom4j dom4j org.jboss.naming jnp-client 5.0.3.GA oswego-concurrent concurrent 1.3.4-jboss-update1 org.jboss.ejb3 jboss-ejb3-proxy-clustered 1.0.1 client org.jboss.ejb3 jboss-ejb3-proxy-impl org.jboss.ejb3 jboss-ejb3-proxy-spi org.jboss.cluster jboss-ha-server-api org.jboss.ejb3 jboss-ejb3-proxy-spi 1.0.0 client org.jboss.ejb3 jboss-ejb3-proxy-impl 1.0.2 client org.jboss.aspects jboss-remoting-aspects org.jboss.ejb3 jboss-ejb3-common org.jboss.ejb3 jboss-ejb3-proxy-spi org.jboss.ejb3 jboss-ejb3-interceptors org.jboss.metadata jboss-metadata org.jboss.naming jnpserver org.jboss.ejb3 jboss-ejb3-core 1.1.5 client javassist javassist org.hibernate hibernate org.hibernate hibernate-entitymanager org.jboss.integration jboss-jca-spi org.jboss jboss-vfs org.jboss.aop jboss-aop org.jboss.aop jboss-aop-aspects org.jboss.cache jbosscache-core org.jboss.ejb3 jboss-ejb3-cache org.jboss.ejb3 jboss-ejb3-endpoint org.jboss.ejb3 jboss-ejb3-security org.jboss.ejb3 jboss-ejb3-timerservice-spi org.jboss.ejb3 jboss-ejb3-ext-api-impl org.jboss.ejb3 jboss-ejb3-metadata org.jboss.ejb3 jboss-ejb3-proxy-clustered org.jboss.ejb3 jboss-ejb3-transactions org.jboss.javaee jboss-ejb-api org.jboss.javaee jboss-jacc-api org.jboss.javaee jboss-jca-api org.jboss.javaee jboss-jms-api org.jboss.jpa jboss-jpa-deployers org.jboss.metadata jboss-metadata org.jboss.microcontainer jboss-kernel org.jboss.security jbosssx org.jboss.ws jbossws-spi quartz quartz sun-jaxws jaxws-api sun-jaxws jsr181-api org.jboss.aspects jboss-remoting-aspects org.jboss.cluster jboss-ha-server-api org.jboss.ejb3 jboss-ejb3-common org.jboss.ejb3 jboss-ejb3-interceptors org.jboss.ejb3 jboss-ejb3-proxy-impl org.jboss.ejb3 jboss-ejb3-proxy-spi org.jboss.remoting jboss-remoting 2.5.1 org.jboss.deployers jboss-deployers-core-spi 2.0.7.GA org.jboss.deployers jboss-deployers-core 2.0.7.GA org.jboss.jbossas jboss-as-main 5.1.0.GA client org.jboss.bootstrap jboss-bootstrap gnu-getopt getopt log4j log4j org.jboss.logbridge jboss-logbridge org.jboss.jbossas jboss-as-j2se 5.1.0.GA org.jboss.integration jboss-classloading-spi apache-xerces xml-apis org.jboss.ejb3 jboss-ejb3-ext-api 1.0.0 org.jboss.javaee jboss-ejb-api org.jboss.metadata jboss-metadata org.jboss.jbossas jboss-as-server 5.1.0.GA client sun-jaxb jaxb-api org.jboss.jbossas jboss-as-deployment org.jboss.bootstrap jboss-bootstrap org.jboss.integration jboss-deployment-spi org.jboss.jpa jboss-jpa-deployers org.jboss.security jbosssx log4j log4j org.jboss.jbossas jboss-as-system-jmx org.jboss.jbossas jboss-as-jmx org.jboss.jbossas jboss-as-system org.jboss.integration jboss-transaction-spi org.jboss.javaee jboss-jacc-api org.jboss.javaee jboss-jms-api org.jboss.ws.native jbossws-native-saaj org.jboss.ws.native jbossws-native-jaxws javax.security jaas org.jboss.javaee jboss-jca-api bcel bcel jpl-util jpl-util jpl-pattern jpl-pattern org.jboss jbossxb org.jboss.naming jnp-server gnu-getopt getopt org.jboss.metadata jboss-metadata org.jboss.javaee jboss-ejb-api org.jboss.naming jnpserver org.jboss.ejb3 jboss-ejb3-security 1.0.0 client org.jboss.aspects jboss-current-invocation-aspects org.jboss.ejb3 jboss-ejb3-interceptors org.jboss.security jbosssx org.jboss.javaee jboss-jacc-api org.jboss.ejb3 jboss-ejb3-ext-api-impl org.jboss.aop jboss-aop org.jboss.ejb3 jboss-ejb3-metadata org.jboss.metadata jboss-metadata org.jboss.security jbosssx-client 2.0.3.SP1 org.jboss.deployers jboss-deployers-client 2.0.7.GA org.jboss.deployers jboss-deployers-client-spi 2.0.7.GA org.jboss.man jboss-managed org.jboss.jbossas jboss-as-system-jmx 5.1.0.GA client apache-xerces xml-apis org.jboss jboss-vfs org.jboss jbossxb org.jboss.deployers jboss-deployers-impl org.jboss.deployers jboss-deployers-structure-spi org.jboss.deployers jboss-deployers-vfs org.jboss.deployers jboss-deployers-vfs-spi org.jboss.bootstrap jboss-bootstrap org.jboss.jbossas jboss-as-system org.jboss.jbossas jboss-as-jmx org.jboss.microcontainer jboss-dependency org.jboss.microcontainer jboss-kernel org.jboss.slf4j slf4j-jboss-logging 1.0.2.GA org.jboss.logging jboss-logging-jdk 2.1.0.GA org.jboss.logging jboss-logging-log4j 2.1.0.GA log4j log4j org.jboss.logging jboss-logging-spi 2.1.0.GA org.jboss.ejb3 jboss-ejb3-common 1.0.0 client org.jboss.microcontainer jboss-kernel org.jboss.metadata jboss-metadata org.jboss.deployers jboss-deployers-spi org.jboss.jbossas jboss-as-server 5.1.0.GA jmx-invoker-adaptor-client sun-jaxb jabx-api org.jboss.jbossas jboss-as-deployment org.jboss.bootstrap jboss-bootstrap org.jboss.integration jboss-deployment-spi org.jboss.jpa jbopss-jpa-deployers org.jboss.security jbosssx org.jboss.metadata jboss-metadata log4j log4j org.jboss.jbossas jboss-as-system-jmx org.jboss.jbossas jboss-as-jmx org.jboss.jbossas jboss-as-system org.jboss.javaee jboss-ejb-api org.jboss.jbossas jboss-as-security org.jboss.integration jboss-transaction-spi org.jboss.javaee jboss-jacc-api org.jboss.jbossas jboss-jms-api org.jboss.ws.native jbossws-native-saaj org.jboss.ws.native jbossws-native-jaxws javax.security jaas org.jboss.javaee jboss-jca-api bcel bcel jpl-util jpl-util jpl-pattern jpl-pattern org.jboss jbossxb org.jboss.naming jnpserver gnu-getopt getopt sun-jaxb jaxb-api org.jboss.jpa jboss-jpa-deployers org.jboss.javaee jboss-jms-api org.jboss.jbossas jboss-as-management 5.1.0.GA jsr77-client org.jboss.deployers jboss-deployers-vfs org.jboss.microcontainer jboss-kernel org.jboss.cl jboss-classloading-vfs org.jboss.jbossas jboss-as-server org.jboss.jbossas jboss-as-system org.jboss.cluster jboss-ha-server-api org.jboss.bootstrap jboss-bootstrap org.jboss.jbossas jboss-as-connector org.jboss.jbossas jboss-as-cluster apache-xerces xml-apis org.jboss.jbossas jboss-as-iiop 5.1.0.GA client apache-avalon avalon-framework apache-xerces xml-apis jacorb jacorb javax.security jaas javax.transcation jta log4j log4j org.jboss.integration jboss-classloading-spi org.jboss.integration jboss-corba-ots-spi org.jboss.integration jboss-transaction-spi org.jboss.javaee jboss-ejb-api org.jboss.jbossas jboss-as-main org.jboss.jbossas jboss-as-server org.jboss.jbossas jboss-as-security org.jboss.jbossas jboss-as-system org.jboss.jbossas jboss-as-system-jmx org.jboss.metadata jboss-metadata javax.transaction jta org.jboss.cluster jboss-ha-client 1.1.1.GA org.jboss.aspects jboss-remoting-aspects org.jboss.jbossas jboss-as-cluster 5.1.0.GA jboss-ha-legacy-client log4j log4j org.jboss.jbossas jboss-as-server jgroups jgroups org.jboss.cluster jboss-ha-server-api org.jboss.cluster jboss-ha-server-cache-spi org.jboss.cluster jboss-ha-server-jbc org.jboss.cluster jboss-ha-server-cache-jbc org.jboss.jbossas jboss-as-system-jmx org.jboss.jbossas jboss-as-system org.jboss.bootstrap jboss-bootstrap javax.transaction jta org.slf4j slf4j-api 1.5.6 org.jboss.aop jboss-aop 2.1.1.GA client apache-xerces xml-apis org.apache.ant ant javassist javassist org.jboss jboss-reflect qdox qdox trove trove log4j log4j org.jboss jboss-common-core 2.2.14.GA org.jboss.security jboss-security-spi 2.0.3.SP1 org.jboss jboss-mdr 2.0.1.GA org.jboss jboss-reflect org.jboss.client jboss-client 5.1.0.CR1 org.apache xmlsec 1.4.2 commons-logging commons-logging 1.1.0.jboss org.jboss.integration jboss-integration 5.1.0.GA jboss.messaging jboss-messaging 1.4.3.GA jboss jboss-serialization 1.0.3.GA org.hibernate ejb3-persistence 1.0.2.GA org.jboss.aspects jboss-remoting-aspects 1.0.2 org.jboss.aop jboss-aop org.jboss.microcontainer jboss-kernel org.jboss.security jbosssx javassist javassist 3.10.0.GA maven-assembly-plugin jar-with-dependencies false JBossClientLibraries-5.10-full make-my-jar-with-dependencies package single
Even here things are not straightforward. (If somebody knows of a better way of doing the following section please tell me).
We need to take the JBossClientLibraries-5.10-full.jar and edit it to remove everything out of the META-INF/maven folder except your artifact details. So in my example everything we be deleted except the sparg.tim folder and its contents.
We can now install this to a repository as an artifact.
Create the Maven EJB Project
After that initial setup things become much the way they should be – simple!
New Project -> Maven EJB Module
Don’t forget to set your Java EE Version to 5, as JBoss does not yet have support for EE 6.
Go File -> new -> Session Bean
Create a business method.
package sparg.tim.simpleejb;
import javax.ejb.Stateless;
/**
*
* @author tsparg
*/
@Stateless
public class HelloBean implements HelloBeanRemote {
public String getMessage() {
return "Hello Netbeans";
}
}
HelloBeanRemote
package sparg.tim.simpleejb;
import javax.ejb.Remote;
/**
*
* @author tsparg
*/
@Remote
public interface HelloBeanRemote {
String getMessage();
}
Right click on your project -> properties -> run and select the JBoss app server.
You can now run the EJB project.
Create NetBeans Platform application
File -> new Project -> Maven -> Maven NetBeans Application
Create the module project with the application (JBossClient-core in my example).
Navigate to your core module and add a dependency – this will be the artifact that we created right in the beginning.
Do the same procedure with the EJB Module you’ve just created, this time you should just be able to click the ‘Open Projects’ tab and select it from there.
Create a new TopComponent, new -> Window.
Make it Open on application Start, in the Editor Position.
I called mine HelloTopComponent.
Drag a Button and label onto the screen
Double click the button to get its ActionHandler.
The pertinent code is
private void btnGetMessageActionPerformed(java.awt.event.ActionEvent evt) {
Properties props = new Properties();
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "127.0.0.1:1099");
InitialContext ctx;
try {
ctx = new InitialContext(properties);
HelloBeanRemote remote = (HelloBeanRemote) ctx.lookup("HelloBean/remote-sparg.tim.simplejb.HelloBeanRemote");
lblOutput.setText(remote.getMessage());
System.out.println(remote.getMessage());
} catch (NamingException ex) {
Exceptions.printStackTrace(ex);
}
}It is important to note that this line
HelloBeanRemote remote = (HelloBeanRemote) ctx.lookup( "HelloBean/remote-sparg.tim.simplejb.HelloBeanRemote");
Will more than likely look different on your system
Now if you’ve managed to get this right, and exercised large amounts of patience – when you click the getMessage button you will get this oh so sweet screen
Although this has taken me a lot longer to figure out than I ever would have guessed, I'm pretty happy just to have the stuff up and running.
It would have been nice for GlassFish to have worked in the role that I have JBoss fulfilling currently - purely because of the tighter integration between GlassFish and the Netbeans communities.
EDIT: please see this post to make this process a whole load shorter










A few comments...
ReplyDeleteIt's unfortunate but true that running a GlassFish client needs several (many) JARs. We have tried to reduce the footprint but it's challenging.
Having said that, there is a way to make sure you get all the JARs. GlassFish includes a package-appclient script. It collects into a JAR all the files you need to run a remote client. You can then transfer this JAR to one or more remote systems, expand it, and then (as you pointed out) refer just to the gf-client.jar in the expanded directory. All the relative references in the Class-Path entries will resolve correctly.
Hi
ReplyDeleteI wasn't aware of the package-appclient script,
would it be possible to highlight it on the GlassFish EJB FAQ?
It's one of the top results on google and people are constantly being referred to it when they have problems getting EJBs to work.
cheers
Tim