วันศุกร์ที่ 25 มิถุนายน พ.ศ. 2553

The Java Project with JAXB 2.2 via NetBeans 6.8

    I've found some exception during testing the Java project with JAXB 2.2 via NetBeans 6.8 as


java.lang.NoClassDefFoundError: 6/8\ide12\modules\ext\jaxb\api
Caused by: java.lang.ClassNotFoundException: 6.8\ide12\modules\ext\jaxb\api
        at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:303)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
        at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316)
Could not find the main class: 6.8\ide12\modules\ext\jaxb\api.  Program will exit.
Exception in thread "main" Java Result: 1

    I had searched via Google and found the solution as following: -

    1. Please right click at your Java project and choose “Properties”. The system will show you a “Project Properties” window.

    2. Within that window, “Categories” panel, Choose the node named “Run”.

    3. You will see the “VM Options:” at the right area, which mentions as

    -Djava.endorsed.dirs=${jaxbwiz.endorsed.dirs}

    4. Please remove this value from your project.

    I would like to thank to a very smart guy here

วันพฤหัสบดีที่ 24 มิถุนายน พ.ศ. 2553

The EJB Session Bean Unit Testing with JUnit (Extended)

    Even the Glassfish Application Server is not to be started and your application also is not to be deployed. You should firstly configure the other required resources, the connection pool for example, by using the Glassfish Application Server Administration console since the configuration is shared between the Glassfish Application Server and EJB embedded container. If not you may face some trouble about the resources missing/absence exception.

    Updated on June 29, 2010

    My fault. The application should be deployed to the Glassfish Application Server once before running the unit testing. If not you will face some trouble about the JNDI looking up.

The EJB Session Bean Unit Testing with JUnit

    The EJB embedded container is introduced by the Glassfish Application Server version 3 and it is a core part for unit testing. It's light weight  and strong enough so that the EJB unit testing can be executed without the starting of Glassfish Application Server. For sure, you may imagine it can be applied for other purpose as same as the embedded database.

    Via NetBean, you can create the JUnit test case and test suit simply by right clicking at the node named “Test Packages” of your EJB project and choose the one you want. The following is the simply step for initiating the EJB embedded container: -

    Creating the JUnit test case or test suit

    1. Declare and initiate the EJB embedded container.

    private static EJBContainer ejbContainer = EJBContainer.createEJBContainer();


    2. Declare and initiate the JNDI context for looking up the EJB.

    private static Context context = ejbContainer.getContext();

    3. Simply use the context object for looking up your EJB and another JavaEE resources via JNDI, for example, The connection pool, the EJB and so on.

    4. The rest is creating your test respectively to you business, unit or others test case by following the JUnit standard.

    Note:

    1. The EJBContainer is javax.ejb.embeddable.EJBContainer

    2. The Context is javax.naming.Context

    Executing the test case with the EJB embedded container

    The prerequisite

    1. The EJB application is not required to be deployed to the Glassfish Application Server

    2. The Glassfish Application Server must not be started since the ports will be clashed since the embedded will share the same ports.

    The execution

    Just simply right click at your test case or test suit and choose “Run File”.

The EJB Session Bean as a Business Services

    I still keep following my integrating concept by treating every single integrated point as an interface. This business services is not an exception. I treat it like a main program for each public services. It also integrates to among of the lower layer, the EJB Session Bean which wraps the JPA Entity with purpose to hide the complexity and difficulty from the caller. It is one and only one who know the complexity of its JPA Entity, including with its business logic.

    Since it is the business services which is published as a public accessing remotely by among of others, The interface should be annotated as @Remote to ensure the remote accessing. Again I also create an abstract POJO which implements that interface and wraps the common activities. The business services session bean will be derived from this abstract class and it is annotated as @Stateless

    Note:

    @Remote is an annotation for the interface and declaring it to be accessed remotely.

    @Stateless is annotation for the POJO and declaring it to be a stateless session bean.
   

The EJB Session Bean for wrapping the JPA Entity

 
    My expectation is generating the JPA Entity by using the NetBeans or other tools. It does not suppose to be modified by hand. If there is any changing at the database layer, I will regenerate it.

    I decide to create a EJB Session Bean for wrapping the basic functions for integrating with the JPA Entity, The set of Create, Read, Update , Delete (CRUD) functions, especially the variety of finding function. I hope it may help to increase the transparent JPA Entity changing. I treat this session bean as an interface for any required integrating by the other through the JPA entity, as long as there is no interface changing, there is also no the client changing, too.

    Furthermore, this session bean should be accessed locally, since the other should not know how to manage this JPA entity. The difficulty and complexity should be hidden by wrapping as a business services, note I will update about it later.

    I create the interface by annotating it as @Local to ensure the local accessing. The good news is the session bean can be derived from any POJO. I also wrap the common activity to the abstract class which implements that interface. The wrapping session bean will be derived from this abstract class and it is annotated as @Stateless

    Note:

    @Local is an annotation for the interface and declaring it to be accessed locally.

    @Stateless is annotation for the POJO and declaring it to be a stateless session bean.
  

The POJO for wrapping the JPA Entity

    Regarding to my opinion, there are 2 types of entity attributes (fields). The one must be persisted at the storage, the data base is an example, the another one is the  temporary which is available for each business, the calculated attributes(fields), the age which is calculated from the date of birth for example.

    Since it is a quick travel for updating and capturing the new technology, I do not have enough time to move further to the JPA Entity inheritance. I decide to create a wrapping class which contains the JPA Entity as its attribute and adding the other attributes which is a temporary entity attributes (fields).  I will use it as a data bean for integrating among my application from end-to-end, the presentation layer through the JPA layer.

    I hope I may have more time to come back to this state and investigating further about the good practice for the extended JPA entity.

วันพฤหัสบดีที่ 17 มิถุนายน พ.ศ. 2553

The JPA 2.0: Basic starting

 
      As I've mentioned at my previous post Apache Derby Part 3, about the JPA preparation as creating 3 tables, the master table, the detail table which is one-to-many relationship with master and the look up table which is one-to-one relationship to the master.

      I've created these 3 tables in Apache Derby by mentioning the relationship explicitly via the foreign key constraint. Then I use NetBeans to generate the JPA and create some testing about the basic CRUD and take more attention to the child data management via the POJO accessing through LIST or COLLECTION e.g. create new elements, update or delete elements. For sure, when save the parent object, all related child objects changing will be applied  automatically without any line of code.

      I finally found it is named a cascading event and orphan removal based on the relationship among the entities. Then it's quite lucky I define that relationship explicitly so that the further investigating and trying is not required. I, personally, though It is nice to follow the standard.

      Please note, my JPA example code follows the “Java EE 5 Tutorial”, Part V: Persistence”. You can download it from Sun/Oracle web site or search it via Google, it will take you to the downloading area.

      Even I follow the Java EE 5 example code, it is worked fine at the Java EE 6: JPA 2.0 as well. The difference is via the JPA 1.x, I need to manage the detail changing by implement some coding and keep tracking and maintaining states by myself explicitly, but not for the JPA 2.0, all changing will be done by the JPA engine as mentioned above.

      As the subject of this article, it is a basic starting. I will quick jump to the EJB 3.1 with purpose to capture and understand the whole big picture of new technology as fast as possible. I prefer the iterative action for my experimental learning by starting from the total picture and the move further to the detail part over and over.
 

วันจันทร์ที่ 14 มิถุนายน พ.ศ. 2553

The Bottom-up approach: From the database through the presentation

      I've decided the road map for my journey from my opinion, by traveling from the back-end as a database storage through the front-end, the presentation. I love this approach while I'm in the development phase. It ensure the basement is strong enough before moving to the top as same as the building construction. The decoration should come last.

      I understand this approach may not meet the real world implementation. Since the front-end, especially look&feel may be the most important for the impression and satisfaction at the first look. People always rush to see what I make for them instead of focusing what their business want.

      The middle-out approach is used often to meet both of the strong base development and the people impression and satisfaction. The strong and flexible interfaces between back-end and front-end is the very first item. Then the front-end and back-end can be done simultaneously with the highest respect to that interfaces. We will meet at that line is my often word for reminding myself.

      During the developing, the changing must be occurred for sure. The whole system will be effected only the interfaces, I mean only on the integration part. As long as the look&feel is nice and the system can serves their business requirement, it is enough to achieve that project.

      I thought, before I can do the middle-out, the bottom-up must be understood first. I need to see the big picture from end-to-end before I make any applying.

      The road map overview

      The persistence

         It will be implemented by using the JPA

      The business processing

         It will be implemented by using the EJB, especially focusing to the integration via the interfaces such as web services(SOAP/RESTful). Both of synchronous and asynchronous integration will be focused. I'm thinking of  the messaging approach, the JMS and/or email

      The presentation

         It will be implemented by using the newly Java Server Face (JSF) 2.x


      Firstly I will focus on the JavaEE standard component. If it is success I will move further to the non-standard, the third party tool, for better implementation. (I also hope it is better)

      I will make a little 2 projects by following this approach and looking forward to integrating them via the Service Oriented Architecture (SOA) approach and tools.
 

วันศุกร์ที่ 11 มิถุนายน พ.ศ. 2553

Apache Derby Part 3

      You can use the SQL client tool, such as "SQuirreL SQL Client" for creating the tables and managing your data. At the first time, even you log in as your decided user name, the schema that related to user name has not be presented. It will presented after you have finished creating a least one table.    

      My previous post mention about "the system will prompt you to provide the default schema, at the moment please choose "APP". At the moment, you have your own schema which is related to your user name already. After you connect  to your database via NetBeans you can extract your connection and choose your schema as a default schema by right click at the schema which same as your user name and choose "Set as Default Schema".
  
      It's nice to create some tables for further using via the JPA. I prefer to have at least 3 tables as following: -
      1. The master table as a parent.
      2. The detail table as a child of the master with one-to-many relationship.
      3. The lookup table for the master table with one-to-one relationship, e.g. the constant table which contains code and description.
  
      Since someone told me that there is an interesting feature for Java EE 6: JPA 2.0, so that you can manage the child data via the POJO accessing through LIST or COLLECTION e.g. create new elements, update or delete elements. When save the parent object, all related child objects changing will be applied  automatically without any line of code. I'm not sure if it is called "Cascading Persist" or not.
  
      Later I will find further information and try my best to prove it.
 

Apache Derby Part 2

      I would like to highlight, if you have finished installed the netbeans 6.8 together with the Glassfish V3, The Apache Derby is installed for your development automatically, it is named JavaDB. Anyhow when you move to the SIT/UAT/PROD, it should has a dedicated database server. Then it may nice if you have an experience and familiar about it instead of only the default development environment.

      The database creation:
     
         Case1 : use the pre-installed by netbeans 6.8 and GF v3
     
            The database location:
           
               You can find it by navigating through netbeans by following step: -
              
               1. Go to "Services" --> "Databases" ---> "Java DB".
              
               2. Right click at "Java DB" node, at the pop-up menu choose "properties". The system will give you information about "Java DB Installation path" and "Database Location".
           
            The database version:
           
               As my tracing through the netbeans as the following step: -
              
               1. Go to "Services" --> "Databases" ---> "Drivers" ---> "Java DB (Network)"
                 
               2. Right click at "Java DB (Network)" node, at the pop-up menu choose "customize". The system will give you a location of Apache Derby JDBC jar file.
           
               3. After I had got the "MANIFEST.MF" from that jar file,I got the information it is a version 10.5.3
           
           
            The database creation:
           
               1. Go to "Services" --> "Databases" ---> "Java DB".
              
               2. Right click at "Java DB" node, at the pop-up menu choose "Create Database...". The system will prompt you to provide information about "Database Name", "User Name" and "Password".  Please note it will give you a "Database Location" as well.
           
               3. The "Connection" to the created database will be added to your environment automatically. For example, you may see this connection information.
           
               "jdbc:derby://localhost:1527/[your db name]"
   

         Case2 : use the separated installed
        
            The database location:
           
               By default, it is a folder that you execute the command to start the Apache Derby. Later I will mention how to customize.
           
            The database version:
           
               Regarding to my previous post, it is a version 10.6
              
            The new driver registration:
           
               Since the default driver is version 10.5.3 as I mentioned above, the version 10.6 driver should be registered by the following step: -
           
               1. Go to "Services" --> "Databases" ---> "Drivers"
              
               2. Right click at the "Drivers" node, at the pop-up menu choose "New Driver...". The system will prompt you to provide the following information:-
           
               "Driver File": The full path to the "derbyclient.jar", by default it is in [Derby_Home]/lib"
              
               "Driver Class": The will be selected automatically by the system, Anyhow you are allowed to change.
           
               "Name": The display name of your new registered driver.
              
            The database creation during the connection is performed:
           
               1. Go to "Database"
              
               2. Right click at "Database"node, at the pop-up menu choose "New Connection...". The system will prompt you to provide the following information.
           
               "Data Input Mode": I prefer choosing "Field Entry". If you have an experience about it, you can prefer "Direct URL Entry".
           
               "Driver Name": Choose you previous created.
              
               "Host": I prefer localhost
              
               "Port": I prefer default port 1527.
              
               "Database": The database name. Please note, if you provide only name, the database will be store at the default location. Anyhow you can specify the full path to your decided location. For example
           
              "c:/[My_Location]/[My_DB_Name]"
              
               "User Name":
              
               "Password":
              
               "Additional Props": I prefer "create=true". If you have any any additional property, it can be separated by comma ",". Please note, this option will create the database automatically along with the specified user name and password respectively. If the database is crated once, this option will be ignored.
           
               "Show JDBC URL": I prefer to check this checkbox and copy the JDBC URL for further using, such as the database management via the "SQuirreL SQL Client" or other tools.
           
               3. Click "OK" when you finish,the system will create the database if it is not exited. The system will prompt you to provide the default schema, at the moment please choose "APP".
           
      At the moment you have finished creating your own database. The next post will take you to create tables. Please stay tuned.

Apache Derby Part 1

   Preparation:

      You need to download the latest official released of Apache Derby here.
  
      It is archived as a ZIP and TAR.GZ format, Since I'm in the Windows environment,I choose the ZIP format. Please note, it's nice to download all thing for further deploying on the multi-platform environment.

   Installation:
 
      It is a ready to run,then you can extract it to your decided folder.
 
   Overview:
 
      The extracted folder contains a very useful documentation for getting starting as [Derby_Home]/docs. There are both of HTML and PDF. The rest of this post will follows the [Derby_Home]/docs/pdf/getstart/getstartderby.pdf  and [Derby_Home]/docs/pdf/adminguide/derbyadmin.pdf

   Quick First Run:
 
      Go to the [Derby_Home]/bin and execute the "startNetworkServer",It will be listen on the default port as 1527. Please note:

     - By default it will listen to the requests only on loopback(localhost) address.
   
      - You need to execute the "StopNetworkServer" everytimes when you finish using.
   
      - If you would like to let it listen on the difference port, please use the following command for starting up.
   
           startNetworkServer -p [port]
   
      - If you would like to let it listing on difference host and port, please use the following command for starting up.
   
           startNetworkServer -h [host] -p [port] ; [host] is a host name or IP
   
     - If you start with the additional option, such as -p and/or -h, You need to provide the same option to the "stopNetworkServer" as well. For example
   
         stopNetworkServer -p [port]
   
         stopNetworkServer -h [host] -p [port]
   
      At the moment you have finished preparing the Apache Derby already, the next  post on part 2 will take you to create the database. Anyhow it's nice to capture the 2 previous mentioned documents before moving to the next.

วันพฤหัสบดีที่ 10 มิถุนายน พ.ศ. 2553

My development tools and environment(Updated)

   My big mistake is the netbean 6.7.1 only support the glassfish version 3 prelude only. Since nowadays the glassfish version 3 is official released already and it is fully supported by newer version of netbeans, the version 6.8 or above. Please not at the moment, the version 6.9 is released as a RC2 and will be final around June 16, 2010.

   I will install all version of netbeans on my laptop, V6.7.1, V6.8 and V6.9 for ensuring the technology updated.

   The official feature highlight for netbean 6.8 is as following: -

   Java Enterprise Edition 6

    * Web Projects with Java EE 6 and Java EE 6 Web profiles, EJBs in web applications
    * EJB 3.1 support, EJB project file wizard also supports Singleton session type
    * RESTful web services (JAX-RS 1.1), GlassFish Metro 2.0 web services (JAX-WS 2.2),       JAXB 2.2
    * Java Persistence JPA 2.0, deployment, debugging and profiling with GlassFish v3       application server

   Web Projects with JavaServer Faces 2.0 (Facelets)

    * Code completion, error hints, namespace completion, documentation popups, and tag auto-import for Facelets
    * Editor support for Facelets libraries, composite components, expression language,      including generators for JSF and HTML forms
    * Customizable JSF components palette generates JSF forms and JSF data tables from entities
    * New File wizard generates customizable CRUD (create/read/update/delete) JSF pages from entities
    * Broader usage of annotations instead of deployment descriptors

   You can find more information here
 

วันอังคารที่ 8 มิถุนายน พ.ศ. 2553

My development tools and environment

 
Firstly I use the Eclipse as my master tool and fall in love with it, anyhow at the moment, I seems to be divided to the NetBeans.

Currently I use the NetBeans 6.7.1 as my primary tool. Eclipse still online as a Galileo, for system integration and compattible testing. Please note there are many IDEs for ensuring testing, including with commercial IDEs.

My prefer Application Servers are based on 2 favorite open sources as Glassfish (Version 2.1 and 3) and Apache Tomcat (Version 5.5 and 6.0).

The database, I also give the importance to the the open source as the Apache Derby and MySQL. Please note, The SQuirreL SQL Client is only tool for exploring the database.

The middle-ware is also an open sources as well. For achieving the Service Oriented Architecture (SOA) is prefer the OpenESB, The security middle-ware is OpenSSO which use the OpenDS as a user store.

For the web service development, I always use 2 tools together, the Apache Axis and the Metro.

Even my projects are developed and tested on my laptop machine which is pre-installed as a Windows Vista Home Premium Edition, I always deploy my project to the dedicated server which is a SentOS environment as well.

As you have seen above, I focus on the open source software with purpose to ensure that everyone can start and follow without any costing. The open source software always challenge me on the production environment as well. It give me an energy boost up for supporting. It's very exciting.

Mainly I focus on the new technology, the JavaEE 6 and SOA, but I cannot deny the backward compatibility for my previous production. You will see I always give the attention to the system integration among many versions of the application servers and tools.

Not only open source software, but also the commercial software which I focus, including with Application Server, Database and middle-ware. I hope I may have a chance for sharing about them.
 

Some of my post is private.

   Since some of my post may be private for some reason, they will be encrypted by using the instruction which is mentioned at Create a Semi-Private Blog

   Here is an example for the encrypted text. Please note the password is "1234".

วันจันทร์ที่ 7 มิถุนายน พ.ศ. 2553

I'm a new blogger.

I decide to be a blogger since I prefer the "documentation" instead of the "Recalling" form the "Brain". Even someone may trust their "Brain" and thought they are "Forever Young".


I know the time goes by. I'm not immortal.

The main focus for this blog is keeping my experience as a document and hope it may be useful for other people. Mostly they are from my learning and trying by taking action from reading many books and many web sites. My mistake is included with purpose to share as a lesson learn. Not only my working experience, but also my story too.

Firstly, I reluctant to write in English, since it is my second language. Please note, I'm Thai. Finally I decide to use the English. It is nice starting to improve my English. Internet is one of the best place for practicing.

I hope you will enjoy reading my blog. I will try my best to update frequently. If you have any suggestion or comment, please do not hesitate to reply. Any replying is highly appreciated.