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.
1. Deploying this simple EAR to JBoss default config doesn't work. I had these errors:
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:
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%\bin6. Deploy the EAR to JBoss AS. Or inside NetBeans, right click the project node and choose Undeploy and Deploy
run.bat -c all
cd %JBOSS_HOME%\server\all\deployMake sure it's correctly deployed, checking the output on JBoss console:
copy C:\javahowto\ServletStateless\dist\ServletStateless.ear .
22:27:15,859 INFO [MCKernelAbstraction] installing bean: jboss.j2ee:ear=ServletStateless.ear,jar=ServletState7. Enter the following URL in the browser. Or inside NetBeans right click project node and choose Run.
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:
StatelessSessionBean
22:27:16,984 INFO [TomcatDeployment] deploy, ctxPath=/ServletStateless-war, vfsUrl=ServletStateless.ear/Servl
etStateless-war.war
http://localhost:8080/ServletStateless-war/servlet
, you will see this:Servlet2Stateless:: Please enter your nameSome 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:Maybe because JBoss 5 is still at beta 4?
StatelessSessionBean
22:22:28,171 WARN [HDScanner] Failed to process changes
org.jboss.deployers.client.spi.IncompleteDeploymentException: Summary of incomplete deployments (SEE PREVIOUS
ERRORS FOR DETAILS):
*** CONTEXTS MISSING DEPENDENCIES: Name - Dependency{Required State:Actual State}
jboss.web.deployment:war=/ServletStateless-war
- 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)
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;