How to get Ejb3s to work in JBoss Ide 1.5 =========================================== 2005-06-15, Marc Bonf Schneider Getting Ejb3 to work on your Jboss server ----------------------------------------- Start by downloading the EJB3 preview archive and unpack it to a conveniant location. Set it up accorting to the installation document (found in in the directory where you unpacked EJB3 preview: docs/tutorial/install.html). Setting up the new Server configuration in JBoss IDE 1.5 -------------------------------------------------------- Set up a JDK1.5 compiler in your eclipse environment (should already have done so - but it's good to check) Go to the 'server navigatior' and do a right click in the main area. Select 'configuration'. The manage debug configurations pops up. Do a right click on JBoss 4.0.x and select 'New'. Enter a name for your new configuraqtion, browse to the jboss installation that holds your EJB3 container and make sure to select the 'all' configuration, NOT the 'default'. The rest can remain unchanged, but check that in the JDK tab you have selected your 1.5 jdk. Creating a EJB3 Project ----------------------- Simply create a new EJB3 project. You can call this what you want, but for this example use StatelessEJB3. Click on 'next' and select the jboss configuration which holds the EJB3 implementation. Click 'finish'. In the project properties go to 'Java Compiler', select 'Enable project specific properties' and set the 'compiler compliance level' to '5.0' Now we're ready to go. Getting some EJB3 code ---------------------- We'll start by getting the simple stateless ejb to run with the jboss ide. To see a description of this code look at /docs/tutorial/stateless/stateless.html. The easyest way of getting the code into jboss is copying the contents of the '/docs/tutorial/stateless/src' to the src directory of your created project (which is in your workspace). In the jboss ide right-click your project, select 'refresh' and see the source magically appear. Creating the packaging ---------------------- Select your project, right click to select properties and select packaging. Click 'add...' t add a new packaging, type 'stateless.ejb3', make sure that exploded is not selected and select the project root as the destination directory. Right-click this packaging and select 'add folder...'. In the add folder dialogue browse to the /bin folder, and type '**/*.class' in the includes. Click ok. Running the project ------------------- Right-click your project in the package explorer and select 'Run packaging'. Packaging should now create a stateless.ejb3 file in your project root. Right-Click on this and select 'Deployment'->'Deploy to...'. Select the server that holds the EJB3 container and click ok. The ejb should now be deployed. Right click on 'client.java' in the 'org.jboss.tutorial.stateless.client' package and select 'Run as'->@Java application'. In the console you should now see 1 + 1 = 2 1 - 1 = 0 indicating that the bean works. Congratulations. You've done it. The steps above are the same for almost all the EJB3 examples. Below I've gone through the examples and indicated any differences. The 'Stateful' example ---------------------- Build the EJB3 as described in the stateless example above. The client needs the org.jboss.aspects.remoting.PojiProxy class, so you'll have to include the jboss aspect library to run it: Right-click on your project, and select 'Preferences'. Click 'build path'->'Libraries' and add external jar. Browse to your jboss home and select /server/all/deploy/jboss-aop-jdk50.deployer/jboss-aspect-library-jdk50.jar' Right-click on Client.java and select 'Run as...'->'Java Application' That should be it. The 'Transaction and Security' example -------------------------------------- In Jboss IDE 1.5M1 you have to copy the jboss-ejb3x.jar file to /eclipse/plugins/org.jboss.ide.eclipse.ejb3.wizards.core_1.4.9 as the one included there (and hence also in the EJB3 libraries) breaks the code of the example. This should change with 1.5M2. You could of course find another way but simple copying the file should be the easiest... The transaction and security examples also need some principles, so you have to copy these from the tutorial/security folder into your /src folder (unlike the author of the ejb3 tutorial, the jboss ide usually places .properties files in the src folder). Now you have to extend the packaging to include the properties files: Right-click your security project, select 'Properties'->'Packaging configuration', add the packaging as described in the stateless bean example above. Then add another entry to your .ejb3 file, by right-clicking it, and selecting 'add folder...'. Click 'Project folder', and select the 'src' folder. In the includes type '*.properties' to include all properties files in the src folder, and click ok. Run packaging, deplay, and run the client as java application. You should see the output shown in the tutorial. The message driven bean example ------------------------------- For the message driven bean an service description needs to be copied to the deploy folder before deploying the ejb. Copy the 'queue-example-service.xml' from the tutorial/mdb folder to the /server/all/deploy folder before deploying. To run the client you will have to include the 'jbossmq-client.jar' from your /client directory. (Right-click project->'properties'->'Java Build Path'->'Libraries'->'Add external jar', and select it. Make sure to deploy the 'queue-example-service.xml' before deploying the ejb3, else it won't work. The other ejb3 examples ----------------------- ...should work roughly the same, but might be included in future versions.