A servlet-EJB3 sample on JBoss AS 5 beta

This is a simple project illustrating how to deploy and run an EAR that contains an ejb-jar and .war on JBoss 5 beta 4. This project is completely portable and contains no JBoss-specific configurations. It should also work on any other JavaEE application servers (Glassfish v1, v2, WebLogic 10, etc).

I will take advantage of the sample projects bundled inside NetBeans 6.1 beta (earlier versions should also have them, though I haven't checked). Download the NetBeans bundle that includesJavaEE and Glassfish.

1. Inside NetBeans, press Ctrl-Shift-N to create a new project. In the popup window, under Categories choose Samples | Enterprise, then under Projects on the right panel choose Servlet Stateless.

2. On the next window, accept defaults for Name and Location, then click Finish.

3. Under Project tab, you will see a new enterprise project called ServletStateless, which contains 2 sub-projects: ServletStateless-ejb and ServletStateless-war. Everything for this project is already in place.

4. Right click the project ServletStateless (the parent project) and choose build. You will see this output: Building jar: C:\javahowto\ServletStateless\dist\ServletStateless.ear

5. Start JBoss AS all config (not default config). You can also do it inside NetBeans if JBoss has been set as the target server for this project.
cd %JBOSS_HOME%\bin
run.bat -c all
6. Deploy the EAR to JBoss AS. Or inside NetBeans, right click the project node and choose Undeploy and Deploy
cd %JBOSS_HOME%\server\all\deploy
copy C:\javahowto\ServletStateless\dist\ServletStateless.ear .
Make sure it's correctly deployed, checking the output on JBoss console:
22:27:15,859 INFO  [MCKernelAbstraction] installing bean: jboss.j2ee:ear=ServletStateless.ear,jar=ServletState
less-ejb.jar,name=StatelessSessionBean,service=EJB3 with dependencies:
22:27:15,859 INFO [MCKernelAbstraction] and demands:
22:27:15,859 INFO [MCKernelAbstraction] jboss.ejb:service=EJBTimerService
22:27:15,859 INFO [MCKernelAbstraction] and supplies:
22:27:15,859 INFO [MCKernelAbstraction] Class:enterprise.servlet_stateless_ejb.StatelessSession
22:27:16,843 INFO [EJBContainer] STARTED EJB: enterprise.servlet_stateless_ejb.StatelessSessionBean ejbName:
22:27:16,984 INFO [TomcatDeployment] deploy, ctxPath=/ServletStateless-war, vfsUrl=ServletStateless.ear/Servl
7. Enter the following URL in the browser. Or inside NetBeans right click project node and choose Run.
http://localhost:8080/ServletStateless-war/servlet, you will see this:
 Servlet2Stateless:: Please enter your name
Some notes:

1. Deploying this simple EAR to JBoss default config doesn't work. I had these errors:
22:22:27,937 INFO  [EJBContainer] STARTED EJB: enterprise.servlet_stateless_ejb.StatelessSessionBean ejbName:
22:22:28,171 WARN [HDScanner] Failed to process changes
org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS

*** CONTEXTS MISSING DEPENDENCIES: Name - Dependency{Required State:Actual State}

- jboss.cache:service=TomcatClusteringCache{Start:** NOT FOUND **}
- jboss.cache:service=TomcatClusteringCache{Create:** NOT FOUND **}

*** CONTEXTS IN ERROR: Name - Error

jboss.cache:service=TomcatClusteringCache - ** NOT FOUND **

at org.jboss.deployers.plugins.deployers.DeployersImpl.checkComplete(DeployersImpl.java:576)
at org.jboss.deployers.plugins.main.MainDeployerImpl.checkComplete(MainDeployerImpl.java:559)
at org.jboss.system.server.profileservice.hotdeploy.HDScanner.scan(HDScanner.java:291)
at org.jboss.system.server.profileservice.hotdeploy.HDScanner.run(HDScanner.java:221)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:441)
at java.util.concurrent.FutureTask$Sync.innerRunAndReset(FutureTask.java:317)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:150)
Maybe because JBoss 5 is still at beta 4?

2. In my NetBeans, I set Glassfish as my default target appserver. Your NetBeans should have one target appserver, and I remember NetBeans also supports JBoss, Webspere, WebLogic with plugins. In my projects I also see various deployment descriptors auto-generated by NetBeans. For this simple project you only need web.xml (to specify servlet mapping) and other *.xml files are all redundant.

3. This is the line that injects bean reference to servlet class:

@EJB private StatelessSession sless;


Amit Saha said...


I am Amit, the NetBeans Community Docs Co-ordinator (http://wiki.netbeans.org/wiki/view/CommunityDocs)

Your blog post would make an excellent entry in your tips & tricks section.

Would you be willing to contribute it?

Looking forward to hear from you.

Mail me at amitksaha@netbeans.org


javahowto said...

Hi Amit,
Feel free to use or share it.

coroner said...
This comment has been removed by the author.
coroner said...

Hey man
i am really fed up with this jboss thing. jboss 4 something does not allow DI in the web container and the jboss 5 something allows DI in webapp but does not allow hot deploy. I need to restart the entire jboss in order for the app to work fine. I know it is beta and all but come on who the hell can use it even for simple tests if it can't hot deploy ejb's. The worst part is that the user when faced with a new problem thinks that something is wrong with the code and not the AppSer.

Faced with this stupid problem now i can't really tell whether there is problem with AppSer until i hear it from some other user. So please, if you got any free time check with this hot deployment and re-deployment of an ejb-jar.jar file and let me know.

Thank you very much even if you can't reply to this issue cos the the posts you got here are of so much help.

April 01, 2008 10:12 AM

Anonymous said...

On notes "1. Deploying this simple EAR to JBoss default config doesn't work. I had these errors"

What steps did you take to fix the error?? I'm tried creating a simple ejb3 app using hibernate and jboss 5.x and i'm getting the same error.

javahowto said...

I just avoided deploying to default config; instead deploying it to all config. I just checked that JBoss 5 is still at beta 4 so I wouldn't waste any time debugging this.

Most JBoss EJB 3 docs/samples I've seen use a standalone EJB 3 and they worked well. It seems JBoss has more work to do to integrate EJB with the rest of Java EE.

Anonymous said...

OK, I give up. What URL is the app supposed to be available at?

Anonymous said...

No matter.

rajeev tumkur said...

JBoss5 beta 4 doesn't support hot deployment. It's fixed in JBoss5 CR1. But DI doesn't working properly in JBoss5 CR1 . Hope this will be fixed in CR2.

Anna said...

Great and Useful Article.

Online Java Course

Java Online Training

Java Course Online

J2EE training

online J2EE training

Best Recommended books for Spring framework

Java Interview Questions

Java Training Institutes in Chennai

Java Training in Chennai

J2EE Training in Chennai

java j2ee training institutes in chennai

Unknown said...

I enjoyed on reading your blog post. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article. Please visit my website, Friv 4000 Games is where all the free friv games.
Friv 4000

eMexoT said...

Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.

Dot net training in electronic city

Shanthi Cabs said...

Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us @ Best Travels in Madurai | Tours and Travels in Madurai | Madurai Travels