Monday, August 26, 2013

Launching WebSphere Liberty Profile from MAVEN

Good day ^o^ Finally I have successfully launch WebSphere Liberty Profile from MAVEN. But only in Linux, not in Windows. I wasn't really sure what is happening on Windows? Because when I launch the server directly from command prompt as shown below will immediately return an error.

server.bat start MyServer

Since even command prompt has failed, it will be the same in MAVEN. Anyhow that only happened on Windows. Only Windows will always cause trouble to me! Now my objective is to configuration MAVEN goal like this > clean install liberty:start-server. To achieve this, some workaround is needed.

1. First thing to do is to declare a repository for Liberty Profile in pom.xml as shown below:
 
  
   WASdev
   WASdev Repository
   http://public.dhe.ibm.com/ibmdl/export/pub/software/websphere/wasdev/maven/repository/
   default
   
    false
   
   
    true
   
  
 
2. Then declare a start-server goal as shown below:
  
   com.ibm.websphere.wlp.maven.plugins
   liberty-maven-plugin
   1.0
   
      /home/kokhoe/tool/wlp
      MyInstance
   
   
      
         start-server
         pre-integration-test
         
            start-server
         
         
            200
            /home/kokhoe/tool/wlp/usr/servers/MyInstance/server.xml
         
      
   
   ...
   ...
3. Open the server.xml which I have specified during the step 2 of the MAVEN configuration, add/replace the following code.

*NOTE: The default value of location attribute is without the full path and version number.

To determine the location attribute, this is how I do it. At the beginning of MAVEN configuration, I have this:
    org.huahsin
    WebProject
    0.0.1-SNAPSHOT
    war
That is for MAVEN allocate my web application in repository. With this information, I know that during the install stage life cycle, my application will be installed into following location:

/home/kokhoe/.m2/repository/org/huahsin/WebProject/0.0.1-SNAPSHOT/

By now when MAVEN build is trigger, it will automatically package and deploy, and the server is ready to listening incoming request.

No comments: