Version 11

    Getting Your EJB3 Project Started

     

    The purpose of this page is to provide a skeleton project that you can use to get an EJB3 project started quickly.  It has an ANT script, Eclipse project settings, Eclipse External Tools definitions and some infrastructure like skeleton deployment descriptors and Hibernate Tools configuration files.

     

    Use this if you are starting a brand new EJB3 project and you don't want to start from scratch.

     

    Attached is a .zip file that contains a skeleton Eclipse project.  Unzip its contents and create a new Eclipse Project with it.

     

    Use this to get a head start putting a new EJB3 project together.  This skeleton project includes:

     

    • Eclipse .project and .classpath files so you can import this as an Eclipse project

     

    • An ANT build script:

      • Compile, clean, prepare tagets

      • Package ejb-jar, war, ear targets

      • Deploy/undeploy targets to deploy/undeploy the ear to JBossAS (tested on 4.0.4RC1)

      • Backup target that zips up the project contents, excluding generated files

      • build.properties that allow you to switch databases

      • Targets that let you create, drop and insert test data to your database

      • Test target that runs TestNG and puts the test results as HTML in build/test-results

     

    • SQL scripts that you can use to create/drop a DB schema and insert test data (use this if you are starting completely from scratch and you are more comfortable building your data model first, then using the Hibernate tools to generate the EJB3 entity beans from the data model)

     

    • Eclipse External Tools definitions that allow you to easily run the above ANT targets within the Eclipse IDE.  You can find most of these in the External Tools drop down button, click "External Tools..." to see all of them.

     

      • Backup

      • Build and Deploy

      • Create Database

      • Purge Database

      • Insert Test Data in Database

      • Undeploy

      • Deploy and Run (allows you to run JBossAS via ANT, as opposed to JBoss-IDE)

      • Test

      • et. al.

     

    • EJB-JAR, WAR, EAR, JBossAS DataSource deployment descriptor skeletons

     

    • Unit test infrastructure.  A superclass that your test classes can extend - AbstractTestCase - that provide some convienence methods to start and shutdown the EJB3 embedded server.  The build.xml has a test target that compiles all classes under test/ and any that end with Test.class will be run by TestNG.

     

    Things that are missing:

     

    • No webapp source (an empty WAR with DDs is generated, you can use this as a starting point)

    • You can grab the TestNG Eclipse plugin, but to use it you need to either put the embeddable-ejb3 jars that contain the bootstrap classes in your build class or you have to create your own TestNG debug launchers with the classpaths set up properly.

     

    Things you still need to do manually

     

    The purpose of this project is to help you get a kickstart in creating a project that you can use to quickly begin coding your EJB3 project.  There are, however, a few manual steps you still need to do:

     

    1. Create a new Eclipse project and point the project directory to the contents of the attached zip file.  This will import the project into Eclipse. Do a File->New and select Java Project.  You then select the radio button "create project from existing source"

    2. Create a JBoss-IDE JBoss Server Configuration called "EJB3-Server".  It must point to a JBossAS server that is configured for EJB3.  I tested using JBossAS 4.0.4RC1.  Once you create this, you must restart Eclipse so the build classpath can pick up the JBossAS jars properly.

    3. Modify build.properties to your environment - the settings should be self explanatory.

    4. lib/ directories needs to get populated with the specific JDBC drivers (not shipped in the attached zip to keep the zip file very small).  See the contents.txt in these directories for the names of the JDBC drivers I tested with.  You also need to get the embeddable EJB3 zip and put it in lib/embeddable-ejb3.  Extract jboss-ejb3.jar and put it in the same directory.  See the contents.txt for more info.

    5. Create a Hibernate Console Configuration and configure for your database.  See etc/hibernate/(database) for the hibernate configuration files - tweak these to conform to your database settings.  These are needed if you want to generate EJB3 code from an existing database schema. See the Hibernate Tools tutorials for help.  If you don't plan on generating code from a database, don't worry about this step.

     

    I think that's it - once you do these things, you can generate code using the Hibernate Tools (optional), you can build and deploy your EAR and you can run your app (using either JBoss-IDE to start JBossAS or use the ANT task to run JBossAS if you want to run outside of Eclipse) and you can run tests (which utilize the embeddable EJB3).

     

    More information

     

    See http://www.ericgar.com/2006/10/17/eclipse-jbossas-ejb-30-setup-instructions for some more instructions on setting up with Eclipse.