16 July, 2008

Develop Enterprise Application Using Maven

Maven Integration For Eclipse IDE
- Web site address http://m2eclipse.codehaus.org/
- Eclipse new features web site address http://m2eclipse.sonatype.org/update/

Add Remote Repository For Nexus Index
Adding remote repository into the nexus index, is easy for you to search the dependency library in the remove repository.
Demo

Enterprise Application Structure

hr

|-
hr-biz
|-
hr-common
|-
hr-web
|-
hr-ear


  1. Create HR Parent Project Demo
  2. Create HR Common Module Demo
  3. Create HR Business Logic Module Demo
  4. Create HR Web Module Demo
  5. Create HR Enterprise Module Demo


Human Resource Business Logic

    HR business logic module implement using EJB3 technology, you can copy and paste the dependency settings into the pom.xml file. Below are the dependency needed to add into the project.

  1. EJB 3.0
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-ejb_3.0_spec</artifactId>
        <version>1.0.1</version>
        <scope>provided</scope>
     </dependency>
  2. JPA 3.0
    <dependency>
        <groupId>org.apache.geronimo.specs</groupId>
        <artifactId>geronimo-jpa_3.0_spec</artifactId>
        <version>1.1.1</version>
        <scope>provided</scope>
    </dependency>
  3. Common Library
    <dependency>
         <groupId>biz.sdscom</groupId>
         <artifactId>hr-common</artifactId>
         <version>0.0.1-SNAPSHOT</version>
     </dependency>



Maven ejb plugin will package the project according to the ejb3 specification, maven ejb 3 plugin will needed to add into the pom.xml. see the example below:

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId>
                <configuration>
                    <ejbVersion>3.0</ejbVersion>
                </configuration>
            </plugin>
        </plugins>
    </build>


Create persistence.xml file in src/main/resource/META-INF with the following setting
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0"
xmlns="http://java.sun.com/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
<persistence-unit name="HR-PU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>jdbc/hr</jta-data-source>
<properties>
  <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
  <property name="hibernate.show_sql" value="true"/>
  <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
  <!-- Required by OC4j -->
  <property name="hibernate.query.factory_class" value="org.hibernate.hql.classic.ClassicQueryTranslatorFactory" />
    <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.OrionTransactionManagerLookup" />
    <!-- Required by OC4j -->
</properties>
</persistence-unit>
</persistence>



If your application server require you to add deployment file, you can add your application server deployment file into src/main/resource/META-INF directory.


Full pom.xml listing

<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
  <artifactId>hr</artifactId>
  <groupId>biz.sdscom</groupId>
  <version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>biz.sdscom</groupId>
<artifactId>hr-biz</artifactId>
<name>HR Business Logic</name>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<description />
<dependencies>
  <dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-jpa_3.0_spec</artifactId>
    <version>1.1.1</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-ejb_3.0_spec</artifactId>
    <version>1.0.1</version>
    <scope>provided</scope>
  </dependency>
  <dependency>
    <groupId>biz.sdscom</groupId>
    <artifactId>hr-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>
</dependencies>
<build>
  <plugins>
    <plugin>
      <groupId>org.apache.maven.plugins</groupId>
      <artifactId>maven-ejb-plugin</artifactId>
      <configuration>
        <ejbVersion>3.0</ejbVersion>
      </configuration>
    </plugin>
  </plugins>
</build>
</project>


Human Resource Web Module
Web module will use MyFaces JSF implementation and RichFaces, to add dependency library into project we need to add jboss maven 2 repo into the maven indexs in Eclipse IDE. The repository url is http://repository.jboss.com/maven2/  and using jboss-maven2 as the repository id.
This is the pom.xml content for the web module

<?xml version="1.0" encoding="UTF-8"?>

<project>

  <parent>

    <artifactId>hr</artifactId>

    <groupId>biz.sdscom</groupId>

    <version>0.0.1-SNAPSHOT</version>

  </parent>

  <modelVersion>4.0.0</modelVersion>

  <groupId>biz.sdscom</groupId>

  <artifactId>hr-web</artifactId>

  <packaging>war</packaging>

  <name>HR Web Module</name>

  <version>0.0.1-SNAPSHOT</version>

  <url>http://maven.apache.org</url>

  <build>

    <finalName>hr-web</finalName>

  </build>

  <dependencies>

    <dependency>

    <groupId>junit</groupId>

    <artifactId>junit</artifactId>

    <version>3.8.1</version>

    <scope>test</scope>

  </dependency>

  <dependency>

    <groupId>biz.sdscom</groupId>

    <artifactId>hr-biz</artifactId>

    <version>0.0.1-SNAPSHOT</version>

    <scope>provided</scope>

  </dependency>

  <dependency>

    <groupId>biz.sdscom</groupId>

    <artifactId>hr-common</artifactId>

    <version>0.0.1-SNAPSHOT</version>

  </dependency>

  <dependency>

    <groupId>org.apache.geronimo.specs</groupId>

    <artifactId>geronimo-jsp_2.1_spec</artifactId>

    <version>1.0</version>

    <scope>provided</scope>

  </dependency>

  <dependency>

    <groupId>org.apache.geronimo.specs</groupId>

    <artifactId>geronimo-servlet_2.5_spec</artifactId>

    <version>1.1.2</version>

    <scope>provided</scope>

  </dependency>

  <dependency>

    <groupId>org.apache.myfaces.core</groupId>

    <artifactId>myfaces-api</artifactId>

    <version>1.2.3</version>

  </dependency>

  <dependency>

    <groupId>org.apache.myfaces.core</groupId>

    <artifactId>myfaces-impl</artifactId>

    <version>1.2.3</version>

  </dependency

  <dependency>

    <groupId>org.richfaces.framework</groupId>

    <artifactId>richfaces-api</artifactId>

    <version>3.2.1.GA</version>

  </dependency>

  <dependency> 

    <groupId>org.richfaces.framework</groupId>

    <artifactId>richfaces-impl</artifactId>

    <version>3.2.1.GA</version>

  </dependency>

<dependency>

    <groupId>org.richfaces.ui</groupId>

    <artifactId>richfaces-ui</artifactId>

    <version>3.2.1.GA</version>

  </dependency>

</dependencies> 

</project>


HR Enterprise Module
    This module is to package the project in EAR format to deploy into application server. This example was targeted OC4J 11 Preview 4. Create orion-application.xml  file and put it in the src/main/application/META-INF
File content
<orion-application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/oracleas/schema/orion-application-10_0.xsd"
deployment-version="11.1.1.0.0" default-data-source="jdbc/hr"
schema-major-version="10" schema-minor-version="0">
    <ejb-module remote="false" path="hr-biz-0.0.1-SNAPSHOT.jar" />
     <web-module id="hr-web-0.0.1-SNAPSHOT" path="hr-web-0.0.1-SNAPSHOT.war" />
    <library path="./"/>
     <persistence path="persistence" />
    <jazn provider="XML" />
    <log>
        <file path="hr-application.log" />
     </log>
     <imported-shared-libraries>
        <remove-inherited name="oracle.toplink" />
     </imported-shared-libraries>
</orion-application>


Add dependency and plugin into pom.xml

pom.xml file content
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<parent>
  <artifactId>hr</artifactId>
  <groupId>biz.sdscom</groupId>
  <version>0.0.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>biz.sdscom</groupId>
<artifactId>hr-ear</artifactId>
<packaging>ear</packaging>
<name>HR EAR</name>
<version>0.0.1-SNAPSHOT</version>
<description />
<build>
<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-ear-plugin</artifactId>
    <version>2.3</version>
    <configuration>
      <archive>
        <manifest>
          <addClasspath>true</addClasspath>
        </manifest>
      </archive>
      <modules>
        <webModule>
          <groupId>biz.sdscom</groupId>
          <artifactId>hr-web</artifactId>
          <contextRoot>hr</contextRoot>
        </webModule>
        <ejbModule>
          <groupId>biz.sdscom</groupId>
          <artifactId>hr-biz</artifactId>
        </ejbModule>
        <jarModule>
          <groupId>biz.sdscom</groupId>
          <artifactId>hr-common</artifactId>
        </jarModule>
      </modules>
    </configuration>
  </plugin>
</plugins>
</build>
<dependencies>
  <dependency>
    <groupId>biz.sdscom</groupId>
    <artifactId>hr-biz</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>ejb</type>
  </dependency>
  <dependency>
    <groupId>biz.sdscom</groupId>
    <artifactId>hr-web</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <type>war</type>
  </dependency>
  <dependency>
    <groupId>biz.sdscom</groupId>
    <artifactId>hr-common</artifactId>
    <version>0.0.1-SNAPSHOT</version>
  </dependency>
  <dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>3.2.1.ga</version>
   </dependency>
<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate</artifactId>
   <version>3.2.1.ga</version>
   </dependency>
  </dependencies>
</project>




04 June, 2008

Richfaces Styles Not Display In OC4J 11 Preview 4


Richfaces 3.2 require the xercesImpl.jar and xml-apis.jar which is not available in OC4J 11 Preview 4.

  1. Download xercesImpl.jar and xml-apis.jar from this url look for version 2.7.1

  2. Create a directory named "xerces.xml" in oc4j/lib/java/shared

  3. Changed to the new created directory and create another directory name "2.7"

  4. Unzip the file xalan-j_2_7_1-bin-2jars.tar.gz and copy xercesImpl.jar and xml-apis.jar into oc4j/lib/java/shared/xerces.xml/2.7

  5. Modify your orion-application.xml to add the new shared library, the code are listed below:

    <imported-shared-libraries>
    <remove-inherited name="oracle.xml">
    <import-shared-library name="xerces.xml">
    </import-shared-library>


  6. Modify your oracle server.xml to setup the xerces.xml shared library. Add the code listed below in your server.xml

    <shared-library name="xerces.xml" version="2.7" root-dir="${oracle.home}/lib/java/shared">
    <code-source path="*">
    </shared-library>

03 June, 2008

Deploy Richfaces In To OC4J 11 Preview 4


The OC4J 11 Preview 4 didn't included JSF 1.2.05 which is required my RichFaces 3.2.0 SR1. Follow steps listed below to upgrade the OC4J 11 JSF library to version 1.2.05.
  1. Download the JSF 1.2.05 at this url

  2. Unzip jsf-1_2_05.zip into a temp directory.

  3. Copy jsf-api.jar and jsf-impl.jar in the temp/jsf-1.2_05-b06-FCS/lib directory into temp directory.

  4. Rename the jsf-impl.jar to jsf-ri.jar in the temp directory.

  5. Remove the jsf-api.jar and jsf-ri.jar in the oc4j/lib/java/shared/oracle.jsf/1.2

  6. Copy jsf-ri.jar and jsf-api.jar in temp directory into the oc4j/lib/java/shared/oracle.jsf/1.2

Now you can start your OC4J and console will report the new version of JSF being running on the OC4J.

08 May, 2008

Using Ant To Deploy EAR To OC4J





I just learn how to use Ant build to deploy ejb application into OC4J Version 11.1.1.0 in Eclipse IDE. First need to add the ant-oracle.jar and ant-oracle-classes.jar file into Eclipse Ant. Follow steps listed below to complete the configuration.


  1. Select Windows->Preferences->Ant-Runtime->Classpath->Ant Home Entries.

  2. Click on the Add External Jar button.

  3. The ant-oracle.jar was located at $ORACLE_HOME\ant\lib

  4. The ant-oracle-classes.jar was located at $ORACLE_HOME\j2ee\ant-tasks\ant-oracle-classes.jar



Add the following target into your build file.

<target name="deploy-oc4j" depends="undeploy-oc4j">
<oracle:deploy deployerUri="${deployer.uri}"
userid="${oc4j.admin.user}" password="${oc4j.admin.password}"
file="${dist.dir}/${ear.jar.name}"
deploymentname="${app.name}"
logfile="${deploy.log.dir}/deploy-ear.log"
bindAllWebApps="default-web-site"/>
</target>


Explanation

deployer.uri = deployer:oc4j:localhost:23791
You can change the localhost to the oc4j server you want to deploy and the port 23791 is the default port, you can change according to your setting.

30 April, 2008

Joining Trade Ship


Two months after my last project at iMocha ended, now i am joining Trade Ship Sdn. Bhd. as a software developer started from 14-04-2008. One year, work as freelancer it is a very good experience.

Finally i got a place to stay after fews week of searching. I rented a room near Setiawangsa LRT station, it is easy for me to get to work caused i didn't drive my car to KL.

13 January, 2008

Glassfish JMS Command

./asadmin list-jms-resources virtuoso-cluster

./asadmin list-jmsdest virtuoso-cluster

./asadmin create-jmsdest --desttype queue --target virtuoso-cluster FSGOutboundQueue

./asadmin create-jms-resource --restype javax.jms.Queue --target virtuoso-cluster --enabled=true --property Name=FSGOutboundQueue jms/FSGOutboundQueue

./asadmin create-jms-resource --restype javax.jms.QueueConnectionFactory --target virtuoso-cluster --enabled=true --property Password=guest:UserName=guest jms/MyQueueCF

30 October, 2006

Vmware Appliance FreeNAS

I downloaded the freeNAS from vmware website to set up a Network-Attached Storage in my house. Now my PC running three vmware appliance, one is Ubuntu 6.0.6 server , second one is Ubuntu desktop and last one is freeNAS.

The freeNAS appliance configured with 5 vmware disk, each of the disk size is 100MB. After set up the freeNAS only 200MB disk space left maybe taken up by the OS.

To increase the size of the vmware disk , can use this command:

vmware-vdiskmanager -x sizeGB file.vmdk

The vmware-vdiskmanager command is not included with the vmware player version, need to check the vmware server version have the command or not.