The Source for Java Technology Collaboration
User: Password:



Brian Leonard

Brian Leonard's Blog

Getting Started With EJB 3.0

Posted by bleonard on January 05, 2006 at 12:23 PM | Comments (3)

If you read my bio, you'll see that I have a pretty deep background in J2EE technology. However, over the past year I've been focusing on other technologies, like the eBay SDK for Java and J2ME. In the mean time, J2EE, now Java EE, has sped on past. With the forthcoming release of Java EE 5, things are changing dramatically, specifically with regards to EJBs. Last month JSR 220 - Enterprise JavaBeans 3.0 released its Proposed Final Draft, so I thought this would be a good time to reacquaint myself with the technology. Now, how hard could it be? The sole purpose of EJB 3.0 is to "improve the EJB architecture by reducing its complexity from the developer's point of view". Still, EJB 3.0 introduces the developer to lots of new concepts, like annotations, dependency injection, persistence units and entity managers to name a few.

So I started with a simple stateless session bean example from JBoss' web site. Of course, I wanted to check out the new support for EJB 3.0 coming in the next version of NetBeans, so I thought I share with you my experience.

Getting Started

  • Download JBoss AS 4.0.3 and install it with the EJB 3.0 profile selected.
  • Download a development build of the NetBeans IDE. Choose Java EE 5 as the release version and Daily as the release type.
  • Start the NetBeans IDE and switch to the Runtime tab (Ctrl+5). Right-click the Server's node and add the JBoss Application Server 4.0.3 that you just installed.
  • You now see JBoss Application Server 4.0.3 in the Server's node. Right-click the node and select Start. You'll see the output from the JBoss server log in NetBeans's Output window and the JBoss server node will have green arrow indicating that's it is running:

Fast Track

If you just want to take the project and run, extract StatelessBeans.zip. Open the project in NetBeans. Deploy the project and run Client.java.

Create the Project

  1. Create a new Enterprise EJB Module project named StatelessBeans. Make sure the Server is JBoss and the J2EE version is Java EE 5.0.
  2. Add a new Session Bean (Ctrl+N - look under the Enterprise category) named CalculatorBean. Set the Package to org.jboss.tutorial.stateless.bean. Select the check boxes to create both Remote and Local interfaces.
  3. Expand the Enterprise Beans node of your project to see your CalculatorBean. Double-click it to open the EJB in the editor. Note that it's a simple POJO that implements two interfaces, CalculatorRemote and CalculatorLocal. Also note the @Stateless annotation. That's all that's required for the container to recognize this as a stateless session bean


  4. Now since both the local and remote interfaces will define the same method, create a Java Interface (Ctrl+N) named Calculator that they can both extend and add the following method signatures:
    public int add(int x, int y);
    public int subtract(int x, int y);
  5. Then update the local and remote interfaces to extend Calculator.
  6. Now switch back to the CalculatorBean and place your cursor on the class declaration (with the wavy red line). Right-click the light bulb that appears to implement the local and remote interface methods.


  7. Add the following to the body of the appropriate method:
        return x + y;
        return x - y;
  8. And our EJB is now complete. Before we can deploy it to JBoss however, we need to change the default archive extension name from "jar" to "ejb3". Switch to the Files tab (Ctrl + 2) and open the project.properties file in the nbproject directory. Change the jar.name property from StatlessBeans.jar to StatelessBeans.ejb3 and save the file (Ctrl+S).
  9. We can also delete the generated configuration files as they're empty - the container now knows what to do based on the Annotations. Switch back to the Projects tab (Ctrl+1) and expend the Configuration Files node. Delete ejb-jar.xml and jboss.xml.
  10. Right-click the StatelessBeans project and choose Deploy Project. If all goes well, you'll see the following in the output window:

Create a Test Client

We'll create a simple client to test the EJB.

  1. Create a new Java Main Class (Ctrl + N) named Client. Put it in the package org.jboss.tutorial.stateless.client.
  2. Add the following code to the main method:
        InitialContext ctx = new InitialContext();
        ctx.addToEnvironment("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
        ctx.addToEnvironment("java.naming.factory.url.pkgs", "org.jboss.naming:org.jnp.interfaces");
        ctx.addToEnvironment("java.naming.provider.url","localhost");
        Calculator calculator = (Calculator) ctx.lookup(CalculatorRemote.class.getName());
    
        System.out.println("1 + 1 = " + calculator.add(1, 1));
        System.out.println("1 - 1 = " + calculator.subtract(1, 1));
    
  3. Press Alt+Shift+F to fix the imports.
  4. The compiler's still unhappy. Place your cursor on the InitialContext line and right-click the light bulb that appears to add the throws clause for the NamingException.


  5. Now our JBoss plug-in is missing a couple of libraries required to run this class, so we need to add them. Right-click the Libraries node of the StatelessBeans project and choose Add Library. Click the Manage Libraries button and add a New Library named jboss-aop.deployer. Add jboss-aop-jdk50.jar and jboss-aspect-library-jdk50.jar from the jboss-4.0.3\server\default\deploy\jboss-aop.deployer directory. Click OK to return to the Add Library dialog and then Add Library to add the new library to your project. You now have this library available for any future needs.
  6. Run the Client (Shift+F6) and you'll see the following output:



    Note, to get rid of the log4j warnings, save this log4j.xml to your src/java directory and build the project.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Hi Brian,

    I've just tried this tutorial with Netbeans 5.5 Beta 2 bundled with JBoss but it won't run as it is.

    I downloaded your zip, but when I deploy it I keep getting the error below. Is there something extra we need to do for the more recent Netbeans builds? Are you able to help?

    Thanks!
    Andrew.

    init:
    deps-jar:
    compile-single:
    run-main:
    Exception in thread "main" javax.naming.NameNotFoundException: org.jboss.tutorial.stateless.bean.CalculatorRemote not bound
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
    at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
    at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
    at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:585)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:294)
    at sun.rmi.transport.Transport$1.run(Transport.java:153)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:149)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:460)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:701)
    at java.lang.Thread.run(Thread.java:595)
    at sun.rmi.transport.StreamRemoteCall.exceptionReceivedFromServer(StreamRemoteCall.java:247)
    at sun.rmi.transport.StreamRemoteCall.executeCall(StreamRemoteCall.java:223)
    at sun.rmi.server.UnicastRef.invoke(UnicastRef.java:126)
    at org.jnp.server.NamingServer_Stub.lookup(Unknown Source)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:625)
    at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:587)
    at javax.naming.InitialContext.lookup(InitialContext.java:351)
    at org.jboss.tutorial.stateless.client.Client.main(Client.java:36)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)

    Posted by: abmyers on September 20, 2006 at 08:09 PM

  • Hy. I also faced this time consuming problem with "NameNotFoundException". To resolve this problem you have to change the string

    "Calculator calculator = (Calculator) ctx.lookup(CalculatorRemote.class.getName());"
    to
    Calculator calculator = (Calculator) ctx.lookup("CalculatorBean/remote");

    in Client.java.

    Posted by: mariobalaban on June 04, 2007 at 02:43 AM

  • mature old sex woman
    d cup bikini tops
    border crossing nexus
    free yahoo e greeting card
    chris daughtry myspace
    little white wedding chapel las vegas
    free background colors for myspace
    cabelas big game
    social security act title iv d
    toyota tacoma 4x4 double cab
    sex shop in los angeles
    the hun yellow page xxx
    sim city 4 pc cheat code
    alicia ass big round tit
    edge r rated superstar
    discount glasses kate spade sun
    cube dog featuring ice snoop
    contest thong
    a l p s
    andy m
    play station 2 game manual
    palm beach county sheriff
    free busty porn star
    private amateur photo
    anal porn ass
    automotive power tool
    anal sex video virgin
    free hardcore teen sex vids
    burner download dvd free software
    yahoo golf handicap tracker
    sopranos theme song lyric
    download flash game porn
    free mature picture seduced sex
    hall rental new jersey
    ed edd n eddy game
    bill clinton fox news video
    betting nascar
    naruto flash movie
    free nude male photo
    arctic cat dealer locator
    free animated wedding clipart
    current london time
    married dating
    prentice hall conceptual physics
    female cat fight
    essen germany map
    nude cartoon drawing
    hsn reward
    crime game online puzzle
    barbie costume dancing princess
    7.5 descarga detalles msn
    airport executive orlando
    fisher building city apartment
    text format resume
    enter game leave
    ass in jeans nice
    evanescence music video yahoo
    naked pete pic wentz
    bryant coupon lane outlet store
    xxx porn sex com
    aol first listen music
    airport inn miami north ramada
    foto maduras porn
    free christian blog
    cruise line job employment
    ancient greek god name
    enter game job
    ass licking milf video
    real spanking video free
    definitive definitive edition guide guide java swing

    third
    american art controversy culture history in shock

    visual
    g garvin tvone
    code ohio portsmouth zip
    snoop dog official site
    colorado loveland map
    gallery young nude woman
    gallery of anal sluts
    crate and barrel free shipping
    a3 driver mustek scanner usb
    dell axim review
    sex tip for straight woman from a gay man
    map quest .com
    fuck my big round ass
    top 100 baby name in 2005
    3d download halloween screensaver
    free hun yellow page
    dance love sexy
    porn dvd review
    english horse tack
    kari ann peniche pic
    airline malaysia mas system
    japanese anime coloring pages
    code music myspace pimp video
    paris hilton color sex tape
    home member page profile yahoo
    blow job sport
    family history local source
    2 flavor love reunion show spoiler
    new york city tax map
    map of princeton new jersey
    masturbating woman xxx
    2007 charger dodge srt8
    ask good in interview question
    music video pop n sync
    black teen pussy free video
    halo 2 game variant
    3 d download game initial
    english french translation words
    the promise glen rose texas
    ass pretty sexy
    box mail mounted residential
    amor b by jon lyric tu
    eultram xanga.com
    1973 car dodge nascar picture
    23 detroit wrestlemania wwe
    chart depth espn nba
    playboy celebrity list
    free pc puzzle game download
    news nwa
    90s r b song list
    free black pussy pic
    mack manual service truck
    mail texas yahoo.com
    old navy jobs.com
    runescape guide to make millions
    love music soft
    free live porn show
    free teen lesbian porn movie
    rate nude pic
    mary j b
    artist last name
    love hina rpg download
    jamaican slang dictionary
    944 form irs
    royal palm phoenix
    action black lesbian movie sex
    free porn black man white woman
    county of palm beach garden florida
    google.com alert
    common street drug name
    japan sex movie download
    download earth free google pro
    nyc mta express bus schedule
    dictionary online philippine tagalog
    anime monster sex
    sexy nude guys
    free xxx sex photo
    card non sport sports trading
    belong jessica lyric simpson
    howard stern fan network
    marriott marquis new york
    free rss news feed
    vancouver escort
    free gay hardcore porn video
    gambling hockey league national sports
    dmv spanish washington
    acne early pregnancy sign
    g hot rod unit
    cbs sunday morning
    used ford f 250
    code free halloween layout myspace
    easy game play puzzle sudoku
    wellsfargo.com checkcard
    male long hair style
    nfl players salary cap
    hilton hotel reno nv
    japanese school teen
    cartoon free hardcore movie
    mature porn free amateur movie
    core hard movie porn
    play n skillz the process
    background cool layout myspace
    parent teacher poem
    basenji dog picture
    activate joemicoltd mail yahoo.com
    spy cam sex video
    philippine embassy australia
    dont pain poem really sad
    b free michelle porn
    background black myspace white
    find lyric song wings
    hair length medium style wedding
    adidas tennis shoes
    natural boob sex
    free internet accelerator
    buy jel kamagra
    day love quote
    download msn messenger version 8.0
    harry potter order of the movie
    diddy p tell video
    free sex porn trailer
    seal kiss from a rose lyric
    survivor jenna sex video
    milf seeker xxx
    kc from the howard stern show
    arab free girl hot
    pitbull dog show
    tabers medical dictionary
    chip free poker
    best d lyric song tenacious tribute

    free gay porn trailer video
    exhib amateur
    bird eye view map
    xxx video forum
    ashanti lyric rain
    gay young fucking old man
    job application form free download
    jennifer lopez j lo
    cambridge history islam
    gay sex orgy
    webster online dictionary
    free group pic sex xnxx
    nude male drawing
    kansas city metro map
    nude ordinary photo woman
    by bye good good hinder lyric nothing
    forum hardware video
    free gospel lyric set
    five for fighting love song lyric
    icon marilyn monroe myspace
    halo 2 movie trailer
    california business name register
    the essential cake decorating guide essential

    cook book series
    acne back chest
    african american baby name and meaning
    2 diabetes diet drink type
    resume search texas
    corps info job knot pine
    history of the warfare of science with theology in

    christendom
    african american baby name and meaning
    cartoon free sample sex video
    daily gallery movie porn star
    budget hotel kentucky louisville
    disney euro restaurante
    lil bow wow picture
    paris hilton pic
    courtyard marriott charlotte
    golf resort in southern california
    free online poker roll tournament
    n sync music pop
    adultfriendfinder.com go p59658.subgo2
    naruto character image
    xnxx fisting gallery
    airline cheap find flight flight hotel hotel london ticket
    bank of america home personal banking
    dragon free picture printable
    yahoo india people search
    i love lucy stuff
    f m h magazine
    download free latest netscape version
    donation motorcycle used
    double foot job
    army division patch
    decor home interior magazine
    double anal penetration video
    spades card game rule
    free movie music piano sheet
    auto repair service
    marine corps uniform store
    disney channey com
    costume danica patrick
    free porn gay guys clip
    cafe internet mydsl pldt
    dog girl pharrell snoop that
    i love lucy store
    free black xxx video
    ash episode kiss may pokemon
    high musical school sound track
    over the hills and far away lyric
    setup yahoo email with outlook
    301 better garden home idea r storage stylish
    zip code map of new york state
    green joke philippine pinoy
    beta mail tutorial yahoo
    free web cam sex show
    japanese name meaning
    cbs sportsline fantasy sports
    hate love poem poetry
    6000 dell inspiron laptop
    new movie rental
    video game console uk
    adult fuck interccourse love position sex
    66 episode naruto online watch
    sears outlet ct
    playboy girl of the acc
    human male penis picture scrotum
    celebrity hair style up
    change indiana time
    online sports betting football gambling
    bow brown chris song wow
    hilton jealousy paris song
    by love lyric neyo sexy
    ciara nude photo
    free gay movie muscle video
    best joke mama vote yo
    texas hold em poker online game
    c b r
    ryctiigaloq v watch youtube.com
    luxury car rental san francisco
    gay boy love
    song lyric for love to sing
    horoscope november taurus
    member nwa
    ultrasound at 20 week pregnancy
    music player console
    d double pov
    fan fiction sakura naruto
    k ci all my life lyric
    macys dept store
    back it liar lyric one sunday take taking
    celebrity fake free porn
    banquet chicago hall in
    week 1 of pregnancy
    nasty news video
    time line of event in us history
    blue blue book book kelley kelley rv rv value value
    poem mother to son by langston hughes
    airport pa pittsburgh
    couple making love video clip
    eva fake longoria
    jesse mccartney free music download
    code jump madonna video
    new york business yellow pages
    augustana love lyric more song than
    f free m spanking story
    craigslist baltimore md
    cheat code for spider man for pc
    naruto sasuke video vs
    miami shop tattoo
    homemade anal porn
    dmv new york phone number
    cute teen love poem
    black clip gallery hairy pussy
    energy h houston l p reliant tx
    amateur porn movie home made
    antique dealer association
    driver nascar point
    back door to yahoo game pool
    charity foundation manila philippine
    antique buying cheap dealer restoring savvy selling

    tip
    anal sex trailer video
    famous poem by maya angelou
    the ascension robert w smith
    free nude female screensaver
    old yahoo toolbar
    free ware internet tv
    xxx rated sex video
    movie new something
    game playing role rpg web
    free milf porn gallery
    ca direction driving map yahoo
    interracial porn trailer
    best small dog breed
    free ware password recovery
    amateur milf movie
    manhattan ny zip code
    free image sport
    vintage sex film
    sbc yahoo com
    microsoft window media player update
    christianity short global history
    free movie of naked gay man
    ohare airport delay
    cambridge english dictionary
    blue howard iris pic stern
    group sex trailer
    free casino video poker
    free britney spears pic
    blonde tiffany teen
    lesbian online sex game
    ontario lottery result
    baby boy middle name
    adult video search engine
    rita g porn
    map of st petersburg russia
    anime boy twinks
    where to find zip code
    porn star sarah young
    black fucked getting hardcore pussy sample video
    boy download game pokemon rom
    3 administration basis r sap sap
    sexy lingerie amateur
    halloween border clip art
    add music player to web site
    better business bureau kansas city missouri
    faneuil hall in boston
    7 apple download itunes show tv
    home for sale lake tahoe nevada
    yahoo fantasy football projection
    bleeding early implantation pregnancy
    nbc universal television
    family photo studio
    define prerogative
    big boob tit fuck
    the elements of typographic style
    3 3 episode lost preview season

    Posted by: ronald45 on August 07, 2007 at 08:16 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds