Friday, January 28, 2011

Use Maven to Build ear

The following is an example of using Maven to build a Java ear application. The ear has one web module, one ejb module, and one jar module.

The top level directory

The top directory layout is as follows:
xyz
    xyz-common
    xyz-ear
    xyz-ejb
    xyz-web
    pom.xml

The file pom.xml is the following:
<?xml version="1.0" encoding="UTF-8"?>
    <project xmlns="http://maven.apache.org/POM/4.0.0"        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
      <modelVersion>4.0.0</modelVersion>
    
      <groupId>com.foo.xyz</groupId>
      <artifactId>xyz</artifactId>
      <version>1.0</version>
      <packaging>pom</packaging>
    
      <name>xyzmaven</name>
 
      <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <env>dev</env>
      </properties> 

        <profiles>      
          <profile>
           <id>dev</id>
           <properties>
            <env>dev</env>
           </properties>
          </profile>
          <profile>
           <id>prd</id>
           <properties>
            <env>prd</env>
           </properties>
          </profile>
     </profiles>
      
      <modules>
        <module>xyz-common</module>
        <module>xyz-web</module>
        <module>xyz-ejb</module>
        <module>xyz-ear</module>
      </modules>
</project>

In this top directory, run "mvn clean install" will build and install all the modules. One can also go to each individual module to run "mvn clean install".

xyz-common

This is a jar module that contains common classes used by other modules.
Its content layout:
src
  main
     java
  test
     java
pom.xml

The file pom.xml is as follows.
<?xml version="1.0" encoding="UTF-8"?>
   <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
     <modelVersion>4.0.0</modelVersion>
     <parent>
       <artifactId>xyz</artifactId>
       <groupId>com.foo.xyz</groupId>
       <version>1.0</version>
     </parent>
     <artifactId>xyz-common</artifactId>
     <packaging>jar</packaging>
     <version>1.0</version>
     <name>xyz-common</name>
     <build>
     <plugins>
     
        <plugin>
         <inherited>true</inherited>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
          <source>1.6</source>
          <target>1.6</target>
         </configuration>
        </plugin>
        
        <plugin>
       <groupId>org.apache.maven.plugins</groupId>
       <artifactId>maven-surefire-plugin</artifactId>
       <configuration>
               <skipTests>true</skipTests>
        <testFailureIgnore>true</testFailureIgnore>
       </configuration>
      </plugin>
      
        <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-jar-plugin</artifactId>
         <version>2.3.1</version>
         <executions>
            <execution>
                <goals>
                  <goal>test-jar</goal>    
                </goals>
            </execution>
       </executions>
        </plugin>
     
       </plugins>
     
      </build>
      <dependencies>
       <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>2.5.5</version>
       </dependency>
     
     </dependencies>
     
   </project>
   

Notes:
  1. The test files are skipped.
  2. The goal "test-jar" will generate xyz-common-1.0-tests.jar

xyz-ejb

This is the ejb module. The file structure is the following.
src
    main
        java
        resources
            META-INF
               ejb-jar.xml
               weblogic-ejb-jar.xml
pom.xml


The file pom.xml is as the following:
<?xml version="1.0" encoding="UTF-8"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <artifactId>xyz</artifactId>
        <groupId>com.foo.xyz</groupId>
        <version>1.0</version>
      </parent>
      <artifactId>xyz-ejb</artifactId>
      <version>1.0</version>
      <packaging>jar</packaging>
      <name>xyz-ejb Maven Webapp</name>
      <build>
        <!-- <finalName>xyz-ejb</finalName> -->
        <plugins> 
             <plugin>
         <inherited>true</inherited>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <configuration>
          <source>1.6</source>
          <target>1.6</target>
         </configuration>
             </plugin>
           
           
             <plugin>
         <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-ejb-plugin</artifactId> 
      <version>2.3</version> 
      <configuration>
         <ejbVersion>2.1</ejbVersion>
      </configuration>
             </plugin>
          </plugins>
        
      </build>
      <dependencies>
         <dependency>
           <groupId>com.foo.xyz</groupId>
           <artifactId>xyz-common</artifactId>
           <version>1.0</version>
        </dependency>
        
        <dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
      </dependencies>
    </project>
Notes:
  1. Just run "mvn clean package" will create the xyz-ejb-1.0.jar. It seems that you do not
    need to run "mvn ejb:ejb".
  2. In this example, the ejb version used is the old 2.1 version.

After xyz-ejb-1.0.jar is built successfully, its file layout is as follows:
com
META-INF
   ejb-jar.xml
   weblogic-ejb-jar.xml


xyz-web

This is the web module. The file structure as follows.
src
              main
                     filters
                            filter-dev.properties
                            filter-prd.properties
                     java
                     resources
                            views.properties
                            messages.properties
                     webapp
                            some_jsp_folder
                            WEB-INF
                                   flows
                                   jsp
                                   other_folders
                                   tld
                                   faces-config.xml
                                   web.xml
                                   weblogic.xml
                                   xyz-servlet.xml

       pom.xml


The file pom.xml is as follows.
<?xml version="1.0" encoding="UTF-8"?>
    <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <modelVersion>4.0.0</modelVersion>
      <parent>
        <artifactId>xyz</artifactId>
        <groupId>com.foo.xyz</groupId>
        <version>1.0</version>
      </parent>
      <artifactId>xyz-web</artifactId>
      <version>1.0</version>
      <packaging>war</packaging>
      <name>xyz-web Maven Webapp</name>   
      
      <build>
        <!-- <finalName>xyz</finalName> -->
        <filters>
       <filter>${basedir}/src/main/filters/filter-${env}.properties</filter>
      </filters>
        <resources>
         <resource>
          <directory>${basedir}/src/main/resources</directory>
          <filtering>true</filtering>
         </resource>
    
        
        </resources>
        <plugins>
         <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-compiler-plugin</artifactId>
          <configuration>
           <source>1.6</source>
           <target>1.6</target>
          </configuration>
         </plugin>
      
         <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-surefire-plugin</artifactId>
          <configuration>
           <testFailureIgnore>true</testFailureIgnore>
          </configuration>
         </plugin>
      
        
       <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.0.2</version>
        <configuration>
                <webResources>
              <resource>
         <directory>${basedir}/src/main/webapp/WEB-INF</directory>
         <filtering>true</filtering>
         <targetPath>WEB-INF</targetPath>
           <includes>
             <include>xyz-servlet.xml</include>
             <include>web.xml</include>
             <include>jsp/css/xp.css</include>
             <include>jsp/shared/header_jsf.jsp</include>
             <include>jsp/shared/mainTemplate.xhtml</include>
           </includes>
              </resource>
              
              <resource>
               <directory>${basedir}/src/main/webapp</directory>
               <filtering>true</filtering>
               <includes>
                   <include>fooDir/foo.xhtml</include>
                   <include>css/xp.css</include>
               </includes>
              </resource>
              
           </webResources>
         </configuration>
       </plugin>
      
        </plugins>
     </build>
     
      <dependencies>
                    <dependency>
             <groupId>icefaces.icefaces-facelets</groupId>
             <artifactId>icefaces-facelets</artifactId>
             <version>1.6.2</version>
            </dependency>
            <dependency>
             <groupId>icefaces.icefaces-comps</groupId>
             <artifactId>icefaces-comps</artifactId>
             <version>1.6.2</version>
        </dependency>
      </dependencies>
    </project>
    

Notes:
  1. One important thing is how to filter files. Here maven-war-plugin is used.

After xyz-web-1.0.jar is built successfully, its file layout is as follows:
some_jsp_folder
      WEB-INF
            classes
                  messages.properties
                  views.properties
            flows
            jsp
            other_folders
            tld
            lib
                  icefaces-facelets-1.6.2
                  icefaces-comps-1.6.2.jar
            web.xml
            xyz-servlet.xml
            weblogic.xml
            faces-config.xml


xyz-ear


This is the ear module that is the final product to be deployed. Its file structure is as follows:
src
    main
      application
        APP-INF
          classes
            hibernate
               foo.hbm.xml
            spring
               xyzContext.xml
            log4j.properties     
        META-INF
          application.xml
      filters
          filter-dev.properties
      java
pom.xml



The file pom.xml is as follows:
<?xml version="1.0" encoding="UTF-8"?>
       <project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
         <modelVersion>4.0.0</modelVersion>
         <parent>
           <artifactId>xyz</artifactId>
           <groupId>com.foo.xyz</groupId>
           <version>1.0</version>
         </parent>
         <artifactId>xyz-ear</artifactId>
         <packaging>ear</packaging>
         <version>1.0</version>
         <name>xyz-ear</name>
        
         
           <build>
             <finalName>xyz</finalName>
             <filters>
              <filter>${basedir}/src/main/filters/filter-${env}.properties</filter>
             </filters>
           
             <plugins>
               <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-ear-plugin</artifactId>
                <version>2.4.2</version>
       
                 <!-- configuring the ear plugin -->
                 <configuration>
                    <filtering>true</filtering>
                   <defaultLibBundleDir>APP-INF/lib</defaultLibBundleDir>
       
                   <modules>
                     <webModule>
                       <groupId>com.foo.xyz</groupId>
                       <artifactId>xyz-web</artifactId>
                     </webModule>
                     <ejbModule>
                       <groupId>com.foo.xyz</groupId>
                       <artifactId>xyz-ejb</artifactId>
                     </ejbModule>
                     
                     <jarModule>
                         <groupId>weblogic</groupId>
                         <artifactId>weblogic</artifactId>
                         <excluded>true</excluded>
               </jarModule>
                   </modules>
                 </configuration>
               </plugin>
               
             <plugin>
         <groupId>scm.plugins</groupId>
                <artifactId>scm-wls-plugin</artifactId>
                <configuration>
         <deployName>xyz</deployName>
         <deploymentName>xyzWLdeploy</deploymentName>
         <artifactPath>C:\workshop\xyz\mavenxyz\xyz-ear\target\xyz.ear</artifactPath>
         <adminServerHostName>localhost</adminServerHostName>
         <adminServerPort>7001</adminServerPort>
         <adminServerProtocol>t3</adminServerProtocol>
         <userId>weblogic</userId>
         <password>weblogic1</password>
         <targetNames>xyzAdminServer</targetNames>
         <verbose>false</verbose>
         <debug>false</debug>
         <upload>true</upload>
         <remote>true</remote>
         </configuration>
               </plugin>
          
             </plugins>
           </build>
           
           <dependencies>
                 <!-- web and ejb modules -->
                 <dependency>
                   <groupId>com.foo.xyz</groupId>
                   <artifactId>xyz-ejb</artifactId>
                   <version>1.0</version>
                   <type>ejb</type>
                 </dependency>
                 <dependency>
                   <groupId>com.foo.xyz</groupId>
                   <artifactId>xyz-web</artifactId>
                   <version>1.0</version>
                   <type>war</type>
                 </dependency>
                 
                 <dependency>
                <groupId>com.foo.xyz</groupId>
                <artifactId>xyz-common-test</artifactId>
                <version>1.0</version>
          </dependency>
       
          <dependency>
            <groupId>antlr</groupId> 
            <artifactId>antlr</artifactId> 
            <version>2.7.6</version> 
          </dependency>
      
       </dependencies>
         
       </project>
  

The file application.xml is the following:
<?xml version="1.0" encoding="UTF-8"?>
   <application xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="1.4">
 
   <display-name>XYZ</display-name>
     <module>
       <ejb>xyz-ejb-1.0.jar</ejb>
     </module>
     <module>
       <web>
         <web-uri>xyz-web-1.0.war</web-uri>
         <context-root>xyz</context-root>
       </web>
     </module>
   </application>
Notes:
  1. The scm-wls-plugin plugin in the pom is a customer-made plugin.
  2. The generated ear will contain all the dependent jars in the xyz-common module and put them into the directory APP-INF/lib. If you do not want some of them to be included, use "<excluded>true</excluded>" in the jarModule as is the case for weblogic.jar in the above pom file.
  3. If additional jars are needed for the ear, just add them in <dependencies>.
  4. By configuing filtering to be true in the maven-ear-plugin, it will filter files in the
    application directory.

After the ear is built successfully, the exploded ear has the following file structure.
xyz
    APP-INF
        classes
            hibernate
                foo.hbm.xml
            spring
            xyzContext.xml
            log4j.properties
        lib
            antlr-2.7.6.jar
            other_jars from the xyz-common dependencies
    META-INF
        application.xml
    xyz-ejb-1.0.jar
    xyz-web-1.0.war

Monday, January 10, 2011

How To Show The Actual Command Line That Eclipse Uses To Launch The Java Program?

You can launch a java program in Eclipse. The console view will show the results.
Often times it will be very helpful to know the actual java command line used by Eclipse.
And I often forget how to do that. Here is the answer.
  1. In the menu bar, select Window --> Open Perspective --> Debug.
  2. In the debug view, you can see a simple line of the command you just ran.
  3. Right click on the line and select Properties. You will see the actual command line.

Windows Process Commandline

For a Windows process, you can view it in the Windows Task Manager. By default, Task Manager does not show the command line for the process. But you can go to "View"-->"Select columns..." and then check "Command Line" in the list. Task Manager will display a new column for command lines. But it seems that if the command line is very long, then only part of it will be displayed. There are the following ways to get the full command line.
  1. Download Microsoft's official "Process Explorer". This tool gives more detailed information about the processes. After launching "Process Explorer", you can right-click on a process and then select "Properties". Then click on the "Image" tab to see the full command line.
  2. Use the Windows Management Instrumentation Command-line (WMIC) tool. For example, you can execute the following directly in the Windows command line console:
    wmic path win32_process get name, commandline > commandline.txt
    
    The following will show all available attributes:
    wmic path win32_process get /format:list
    

Friday, January 7, 2011

Concept Clarification of IBM DB2, AS400, Mainframe, etc.

There are many technical names related to DB2, AS400 etc from IBM. These are confusing. Here are some clarification.

DB2 is a relational model database server developed by IBM. The name confusion mainly comes from the various platforms that DB2 runs on. On different platforms, DB2 is different. It has different features and may be even written in different languages. To differentiate products on different platforms, a formal name IBM uses is "product FOR platform". For example, DB2 for OS/390, DB2 for z/OS, DB2 for i.

AS/400 is a system that includes both an operating system (OS/400), DB2, and others.
AS/400 is now called IBM System i (iSeries ), or more recently IBM power system. And its operating system OS/400 is now called IBM i operating system.

z/OS is a 64-bit operating system for mainframe computers, produced by IBM. It is the successor to OS/390, which in turn followed a string of MVS versions.

AS/400 is not a mainframe system. The IBM System i is a midrange computer system for i users. In 2008, IBM announced its integration with the System p platform. The unified product line is called IBM Power Systems and features support for the IBM i (previously known as i5/OS or OS/400), AIX and Linux operating systems.

DB2 UDB stands for DB2 Universal Database. It used to mean DB2 for the Linux-unix-Windows version. Now it can also mean DB2 on mainframe.

At this point, the mainframe version of DB2 UDB and the server version of DB2 UDB were coded in entirely different languages(PL/S for the mainframe and C++ for the server).

DB2 UDB Version 8 for z/OS now requires a 64-bit system.

In 2006, IBM announced "Viper": DB2 9 on both distributed platforms and z/OS.
In 2009, IBM announced "Cobra": DB2 9.7 for LUW(Linux, Unix, Windows).
In 2009, IBM announced DB2 pureScale. It is a database cluster soluction for non-mainframe platforms.
In 2010, IBM announced that DB2 10 for z/OS would enter beta testing.

DB2 for i(the former DB2/400) is very closely incorporated into the operating system of the IBM System i machines.

Reference

[1] http://en.wikipedia.org/wiki/IBM_DB2
[2] http://en.wikipedia.org/wiki/Z/OS
[3]http://search400.techtarget.com/expert/KnowledgebaseAnswer/0,289625,sid3_cid414164,00.html