openejb - 另一個選擇

Download OpenEJB - 另一個選擇

Post on 16-Apr-2017

1.447 views

Category:

Technology

1 download

Embed Size (px)

TRANSCRIPT

  • , http://openhome.cc

  • Java Developer Killer

  • Java SE Development Kit 6

    http://java.sun.com/javase/downloads/index.jsp

    NetBeans 6.5 Java Bundles

    http://www.netbeans.org/downloads/index.html

    Apache OpenEJB 3.1

    http://openejb.apache.org/download.html

    XD

  • USER_HOME/workspace

    c:/workspace

    OpenEJB

    WORKSPACE/openejb-3.1

    c:/workspace/openejb-3.1

  • NetBeans OpenEJB

    NetBeans

    Tools LibrariesNew Library Library Name: OpenEJB

    Library Type: Class Libraries

    OK

    Add JAR/Folder

    OPENEJB_HOME/lib JAR

    Add JAR/Folder

    OK

    OK

  • 50

  • 5 10

    XD

    Copy-and-Paste - -

  • Hello! EJB!...Orz

    EJB

    Resource MDB

    Tomcat EJB

    Tomcat EJB

    Stand-alone ServerOptional

  • Hello! EJB!Orz

    FileNew ProjectJavaJava

    Application

    Project Name: HelloEJB

    Project Location: WORKSPACE

    Finish

    OpenEJB LibrariesAdd Library

    OpenEJB Add Library

  • Hello! EJB!Orz

    OpenEJB

    LibrariesAdd Library

    OpenEJB Add Library

  • Hello! EJB!Orz

    Session Bean Local

    Source PackagesNewJava Interface

    Class Name: HelloLocal

    Package: helloejb

    LAB_FILE/HelloEJB/HelloLocal.txt

  • Hello! EJB!Orz

    Source PackagesNewJava Interface

    Class Name: HelloImpl

    Package: helloejb

    LAB_FILE/HelloEJB/HelloImpl.txt

  • Hello! EJB!Orz

    Glassfish

  • Hello! EJB!Orz

    EJB

  • Hello! EJB!Orz

    Local Server

    OpenEJB can be embedded and treated as

    your very own personal EJB container.

    LAB_FILE/HelloEJB/Main-1.txt

    Properties properties = new Properties();

    properties.setProperty(

    Context.INITIAL_CONTEXT_FACTORY,

    "org.apache.openejb.client.LocalInitialContextFactory");

    properties.put("openejb.home", "C:\\workspace\\openejb-3.1");

    properties.put("openejb.configuration","openejb.conf");

  • Hello! EJB!Orz

    openejb.conf

    HelloEJBNewEmpty File

    FileName: openejb.conf

    LAB_FILE/HelloEJB/openejb.conf.txt

  • Hello! EJB!Orz

    LAB_FILE/HelloEJB/Main-2.txt

    JNDI

    Local

    Remote

    InitialContext context = new InitialContext(properties);

    Object obj = context.lookup("HelloImplLocal");

  • Hello! EJB!Orz

    XD......OK!

    SOLUTION\HelloEJB

  • EJB

  • EJB

    PREPARED_PRJ\EJBUnitTest

    OpenEJB

    NetBeansOpenEJBc:\workspace\openejb-3.1

    Test PackagesNewJUnit Test

  • EJB

    LAB_FILE/EJBUnitTest/HelloLocalTest-1.txt

    LAB_FILE/EJBUnitTest/HelloLocalTest-2.txt

    LAB_FILE/EJBUnitTest/HelloLocalTest-3.txt

    Test Packagestest.helloejb.HelloLocalTest

    Run File

  • EJB

    Tests run: 1, Failures: 0, Errors: 0

    SOLUTION\EJBUnitTest

  • Resource

    EntityManager

    DataSource

    Topic Queue

  • Resource

    Message-Driven BeanMDB PREPARED_PRJ\ResourceInjection

    @Resource Source Packageshelloejb.HelloImpl

    LAB_FILE\ResourceInjection\HelloImpl-1.txt

    LAB_FILE\ResourceInjection\HelloImpl-2.txt

    Message-Driven Bean Source Packageshelloejb.HelloMessage

    LAB_FILE\ResourceInjection\HelloImpl-1.txt

    LAB_FILE\ResourceInjection\HelloImpl-1.txt

  • Resource

    openejb.conf

    NetBeans Files

    LAB_FILE\ResourceInjection\openejb.conf ResourceInjection

    openejb.conf

    DataSourceJMS

    ActiveMQ

    .

  • Resource

  • Resource

    Test Packagestest.helloejb.HelloLocalTest

    Run File

    Tests run: 1, Failures: 0, Errors: 0

    SOLUTION\ResourceInjection

  • Tomcat EJB

    JSP/Servlet

    EJB +

  • Tomcat EJB Tomcat EJB

    openejb.war Tomcat NetBeans Cataline_Base

    USER_HOME\netbeans\6.5\apache-tomcat-6.0.18_base\webapps

    NetBeans Tomcat ServicesServersApache Tomcats

    Start

    Tomcat EJB http://localhost:8084/openejb/

  • Tomcat EJB

    TomcatHello!EJB!Orz

    FileNew ProjectJava WebWeb

    Application

    Project Name: HelloEJBTomcat

    Project Location: WORKSPACE/

    Next

    Server: Apache Tomcat

    Finish

  • Tomcat EJB

    Java EE API

    LibrariesAdd JAR/Border

    OPENEJB_HOME/lib/javaee-api-5.0-1.jar

    package

    Source PackagesNewJava Package

    Package Name: hellloejb

    Finish

  • Tomcat EJB

    Stateless Session Beanhelloejb SOLUTION\HelloEJB\src\helloejb\HelloLocal.java

    SOLUTION\HelloEJB\src\helloejb\HelloImpl.java

    HelloServlet

    Source PackageshelloejbNewServlet

    Class Name: HelloServlet

    Finish

  • Tomcat EJB

    EJB

    processRequest()

    public class HelloServlet extends HttpServlet {

    @EJB

    private HelloLocal hello;

  • Tomcat EJB

    Stateless Session Bean

    HelloServlet-2.txt

    Web

    HelloEJBTomcatClear and Bulid

    HelloEJBTomcatDeploy

    Source Packageshelloejb.HelloServletRun

    ...

    out.println("" + hello.doHello("Orz...") + "");

    ...

  • Tomcat EJB

    SOLUTION\HelloEJBTomcat

  • Tomcat EJB

    Session Bean

    Tomcat Session Bean

    INITIAL_CONTEXT_FACTORY

    PROVIDER_URL

    SOLUTION\HelloEJBTomcat

  • Tomcat EJB

    Session Bean

    @Remote

    public interface HelloRemote {

    public String doHello(String message);

    }

    public class HelloImpl implements HelloLocal, HelloRemote {

    }

  • Tomcat EJB

    ServicesTomcatCleanBuildDeploy

    FileNew ProjectJavaJava Application

    Project Name: HelloClient

    Project Location: WORKSPACE

    Finish

    OpenEJB LibrariesAdd Library

    OpenEJB Add Library

  • Tomcat EJB

    package

    Source PackagesNewJava Package

    Package Name: hellloejb

    Finish

    HelloEJBTomcatHelloRemoteHelloClienthelloejb

  • Tomcat EJB

    Main

    LAB_FILE\HelloClient\Main.txt

    EJB Server

    Properties properties = new Properties();

    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,

    "org.apache.openejb.client.RemoteInitialContextFactory");

    properties.put(Context.PROVIDER_URL,

    "http://127.0.0.1:8084/openejb/ejb");

    InitialContext context = new InitialContext(properties);

    Object obj = context.lookup("HelloImplRemote");

  • Tomcat EJB

    XDOK!

    SOLUTION\HelloEJBTomcat2

  • Stand-alone ServerOptional

  • Stand-alone ServerOptional

    OpenEJB Stand-alone Server

    set OPENEJB_HOME=c:\workspace\openejb-3.1

    set PATH=%OPENEJB_HOME%/bin;%PATH%

    openejb start

  • Stand-alone ServerOptional

    OpenEJB apps

    EJB JAR apps

    OpenEJB

    openejb deploy yourejb.jar

  • Stand-alone ServerOptional

    Session Bean

    @Remote

    public interface HelloRemote {

    Properties properties = new Properties();

    properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,

    "org.apache.openejb.client.RemoteInitialContextFactory");

    InitialContext context = new InitialContext(properties);

    Object obj = context.lookup("HelloImplRemote");

  • Stand-alone ServerOptional

    LAB_FILE\Optional

  • EJB3

    http://doc.openhome.cc

    http://www.manning.com/panda/

    http://oreilly.com/catalog/9780596009786/

    OpenEJB

    http://openejb.apache.org/

    http://openejb.apache.org/examples.html

  • caterpillar@openhome.cc

    http://openhome.cc

    http://openhome.cc,

    caterpillar@openhome.cc

    Thank You