• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to develop a standalone swing application with ejb 3.1

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, Thanks you for your replies.
首先,谢谢你的回复和建议/指导!
Second, sorry about my poor English,
if you understand Chinese, you can read Chinese under the English content.
我的英语很差,如果你懂中文,我想英文下面的中文更能准确的表达我的意思。

I have an idea to develop a standalone swing application
( which can be deployed in any standalone J2SE environment) using EJB 3.1. It means:
我想使用EJB3.1技术开发一个Swing应用程序,并且想让此程序运行于独立的J2SE环境上。这意味着:

  • Using all of ejb 3.1 technology.
    充分利用全部的EJB3.1技术。
  • Can run in the embedded containers. do not need fully j2ee application server.
    不需要部署在完整的J2EE应用服务器上,仅需使用各种嵌入式容器即可。


  • The requirement
    I want the application completely fit the specification.
    I want use all of the ejb3.1 features.
    I want the application can be deployed in the fully j2ee container. and,
    I want the application can be deployed in a standalone j2se jvm environment without any codes modified.

    To make my idea clear, I'll introduce the simplest programs which describe the idea.
    为了清楚的表达我的意思,这里举了一个简单的例子。

    There are 4 important Java classes:
    一共有4个主要的Java类:

  • a) a main class to start up the embedded containers and set the J2EE environment.
    一个含有main方法的类,启动所有嵌入式容器,并完成J2EE环境的初始设置。
  • b) context holder. hold the J2EE context in the swing application.
    上下文持有者。为Swing应用程序持有J2EE上下文。
  • c) a stateless session bean, implements the business logics or accesses the database.
    一个无状态会话Bean。
  • d) a swing client to invoke the stateless session bean
    一个简单的本地客户端调用无状态会话Bean。


  • what I want:
    我想要的结果是:

    a) the main class (StartApp) to start up the embedded containers:


    b) the context holder:


    c) the stateless session bean:


    d) the swing client:


    I've found a way to implement the idea:
    我已经找到了一个实现方法:

    using openejb 3.2.0 snapshot (supports most important ejb3.1 technologies).
    The swing classes can inject ejb by openejb proprietary way,
    and most of the container properties can be set:

    the StartApp class:


    The startApp class init and start the ejb container with configurable properties.
    The Ejb container start when invoke the new InitialContext method.
    When the main thread exits, the container is disposed.

    If I want to inject the EJB reference to a client,
    I must invoke the bind("inject", clientObject) method. openejb container can not do it automatically.
    I think It's not good. If there are a lots of client need ejb inject,
    the client's construct method must be have the "bind("inject", clientObject)" sentence.
    And the openejb performance can not be used in other j2ee container. It is not fit the specification.

    the context holder:

    The ContextHolder class is very simple.
    But I think if use a powerful container, the context holder is not necessary.

    the stateless session bean:

    It's very simple.

    the swing client:

    It's simple. But there is an annotation named "LocalClient".
    If the annotation is not exist, the "ContextHolder.getContext().bind("inject", client);"
    setence in the StartApp class is useless.
    Openejb container use the "LocalClient" annotation to indentify the client.
    I think it's not good, and it is not fit the specification.

    I think there must be another way to implement my idea

    Now I tried to use glassfish embedded container and glassfish embedded acc container.

    I make 3 jars.
    1) startApplication.jar. I want it to init and start the glassfish embedded container and glassfish acc container.
    2) EJBModule.jar. contains all of the ejb components.
    3) EJBClient.jar. the clients which invoke ejb components.

    startApplication.jar
    The pom.xml of startApplication.jar:

    There is only 1 class to init and start the containers.StartApp:

    EJBModule.jar
    the most important dependency in pom.xml:

    There is only 1 class to perform the ejb charator.

    EJBClient.jar
    the most important dependencies in pom.xml

    There are 2 classes in EJBClient.jar:
  • App: provide main method to the glassfish embedded acc container
  • TestClient: the client to invoke ejb components.

  • the App class:

    the TestClient class:


    The problems:
  • I can not start the glassfish embedded ejb container and embedded acc container in the same time/method.
  • I can start the embedded ejb container without acc container, but how can i deploy modules without point out the path of the modules?
  • I can start the embedded acc container without ejb container, but how can i inject the ejbs into the clients?



  • when i run the StartApp class, i got the log and exception:


    If i modified the pom.xml of startApplication.jar , delete the dependency of "glassfish-embedded-all", there are no errors in compile time. but in the run time ,i got the log and exceptions:

    I followed the exception, and I found that the habitat.getComponent(CommandRunner.class) (ConfiguratorImpl.java:68) returns null.
    Then I comment the CommandRunner, CommandResult and GlassFishProperties in the main method of StartApp class. I got the exceptions:

    I think it is about the Deployer. so i comment the Deployer in the StartApp class. then I got the exceptions:

    There are only injects exceptions, I think the acc container runs correctly. but How can i deploy ejb modules on this situation?

    how can i implements my idea? Thanks for your replies!

    Leonard Chen
    regards
    reply
      Bookmark Topic Watch Topic
    • New Topic