Tuesday, August 27, 2013

Deploy war to WebLogic using Maven

First off you need Maven and Weblogic setup in your computer to start this tutorial.
My Weblogic(10.3.6.0) has setup under : C:\Oracle\Middleware.

Set Middleware home :
 
set MW_HOME=C:\Oracle\Middleware

1. Build the plug-in JAR file using the WebLogic JarBuilder Tool (wljarbuilder) under %MW_HOME%/wlserver_10.3/server/lib/ with the following command:
 
java -jar wljarbuilder.jar -profile weblogic-maven-plugin
The weblogic-maven-plugin.jar contains a Project Object Model (pom.xml) file which specifies the groupId, artifactId, version, and packaging of the weblogic-maven-plugin.jar:
 groupId=com.oracle.weblogic
artifactId=weblogic-maven-plugin
version=10.3.6.0
packaging=maven-plugin

2. Extract the pom.xml file from weblogic-maven-plugin.jar under the %MW_HOME% wlserver_10.3/server/lib directory, and then copy the pom.xml file to %MW_HOME%/wlserver_10.3/server/lib.
 
jar xvf %MW_HOME%/wlserver_10.3/server/lib/weblogic-maven-plugin.jar META-INF/maven/com.oracle.weblogic/weblogic-maven-plugin/pom.xml


copy %MW_HOME%/wlserver_10.3/server/lib/META-INF/maven/com.oracle.weblogic/weblogic-maven-plugin/pom.xml  to %MW_HOME%//wlserver_10.3/server/lib/pom.xml

Add following in your project pom.xml file:


3.Provision the weblogic-maven-plugin.jar in your local Maven repository with the following command. However, for a shortened command-line goal invocation of the plug-in, follow the directions in next step 4 before performing this step.
http://docs.oracle.com/cd/E21764_01/web.1111/e13702/maven_deployer.htm
 
mvn install:install-file -Dfile=%MW_HOME%/wlserver_10.3/server/lib/weblogic-maven-plugin.jar -DpomFile=pom.xml



4.
  you can shorten the full invocation of the plug-in by providing a pom.xml file  and modifying the settings.xml file located in your $HOME/.m2 directory, before you provision the plug-in in your Maven repository
  1. Change the settings.xml file as follows:
    
    
    
       
       com.oracle.weblogic
     

 b. Replace the %MW_HOME%/wlserver_10.3/server/lib/pom.xml file with the following(Use same version that was in the pom.xml):




  4.0.0
  com.oracle.weblogic
  weblogic-maven-plugin
  maven-plugin
  10.3.4
  Maven Mojo Archetype
  http://maven.apache.org
  
    
      org.apache.maven
      maven-plugin-api
      2.0
    
  
 
  
   
      
       maven-plugin-plugin
       2.3
       
         weblogic
       
      
    
  
 


From within MW_HOME/wlserver_10.3/server/lib/, run the mvn install command.

mvn install

From within MW_HOME/wlserver_10.3/server/lib/, provision the weblogic-maven-plugin.jar in your local Maven repository as follows:

mvn install:install-file -Dfile=%MW_HOME%/wlserver_10.3/server/lib/weblogic-maven-plugin.jar -DpomFile=pom.xml

Now, you can use a shortened command-line goal invocation, such as:

mvn weblogic:deploy

Deployment Goals
weblogic.deploy
weblogic:undeploy
weblogic:redeploy
weblogic:start-app
weblogic:stop-app
weblogic:list-apps
weblogic:update-app
weblogic:help


  

Create Oracle Stored Procedure example

Following is a basic oracle store procedure example:

CREATE OR REPLACE PROCEDURE procPrintHelloWorld
IS

 usr_id VARCHAR2(20):=' sujan ';
BEGIN
 
  DBMS_OUTPUT.PUT_LINE('Hello World!'|| usr_id);
 
END;
/
To see output on console you need to run following command.

 set serveroutput on size 30000;

Run store procedure:


 EXEC procPrintHelloWorld;

If you get any compilation error, run following command to display it.

SHOW ERRORS

Friday, August 16, 2013

Add SVN email notification

SVN email notification is important when many programmer involves  in software development. For example, you are working on module and other programmers are using that. So if you check-in updated the classes , you have to notify other developers that module has been updated.

SVN provide post commit hook option, there you can add any script or programme that would be execute after SVN commit. Here I will add email notification in post-commit hook script.

I have create a repository in /apps/subversion/hsolite/.
Using ls command you can see default directories created under repository. There is a directory called hooks where you will put you post-commit script. When any user will commit in SVN, post-commit script will be execute.


To send email notification you need find out "mailer.py" and "mailer.conf"

[root@domU-12-31-39-09-29-13 hsolite]# find / -name "mailer.py"
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.py


[root@domU-12-31-39-09-29-13 hsolite]#  find / -name "mailer.conf"
/usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer.conf

Now copy the mailer.py and mailer.conf  under /apps/subversion/hsolite/hooks and  /apps/subversion/hsolite/ respectively.

[root@domU-12-31-39-09-29-13 hsolite]#  cp /usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/mailer.py   /apps/subversion/hsolite/hooks/mailer.py

[root@domU-12-31-39-09-29-13 hsolite]# cp  /usr/share/doc/subversion-1.6.11/tools/hook-scripts/mailer/tests/mailer.conf   /apps/subversion/hsolite//mailer.conf

Now edit the mailer.conf and override following properties

mail_command = /usr/sbin/sendmail
commit_subject_prefix = [svn-myproject]
from_addr = noreply@mydomain.com
to_addr = commits-myproject@mydomain.com  # this is a mailing list


Under hooks directory you will find "post-commit.tmpl" that you need to rename to "post-commit".

Replace "post-commit" script  contains with the following snippet.
------------------------------------------------
#!/bin/sh

REPOS="$1"
REV="$2"

/apps/subversion/hsolite/hooks/mailer.py commit "$REPOS" "$REV" /apps/subversion/hsolite/mailer.conf

-------------------------------------------------------

Make sure "post-commit" is executable.
[root@domU-12-31-39-09-29-13 hsolite]# chmod +x post-commit


Testing :
Using svnlook  yon can get latest revision number.

[root@domU-12-31-39-09-29-13 ~]# svnlook info /apps/subversion/hsolite/
sujankn
2013-08-16 07:41:29 -0400 (Fri, 16 Aug 2013)
0

[root@domU-12-31-39-09-29-13 ~]# svnlook youngest /apps/subversion/hsolite/
2850

Test the hook script:

[root@domU-12-31-39-09-29-13 ~]# REPOS=/apps/subversion/hsolite/
[root@domU-12-31-39-09-29-13 ~]#  REV=2850
[root@domU-12-31-39-09-29-13 ~]#  "$REPOS"/hooks/mailer.py commit "$REPOS" $REV "$REPOS"/mailer.conf 

After run above command you should receive email notification with revision number 2850

[root@domU-12-31-39-09-29-13 ~]# REPOS=/apps/subversion/hsolite/
[root@domU-12-31-39-09-29-13 ~]#  REV=2850
[root@domU-12-31-39-09-29-13 ~]#   sh $REPOS/hooks/post-commit  $REPOS$REV
If post-commit script run successfully then commit some files in SVN then check your email inbox for notification.

Monday, August 5, 2013

Weblogic JPA 2.0 configuration

If you find following exception in webloginc while running JPA 2.0 web application
Caused By: java.lang.NoSuchMethodError: javax.persistence.spi.PersistenceUnitInfo.getValidationMode()Ljavax/persistence/ValidationMode;

you need to add following line in commEnv.cmd( located at %BEA_HOME%\wlserver_10.3\common\bin\) just after  "set BEA_HOME=C:\Oracle\Middleware"


set PRE_CLASSPATH=%BEA_HOME%\modules\javax.persistence_1.1.0.0_2-0.jar;%BEA_HOME%\modules\com.oracle.jpa2support_1.0.0.0_2-1.jar

Then restart your server again.


Increase Weblogic heap size

Go to your domain bin directory and find setDomainEnv.cmd.
For example:
C:\Oracle\Middleware\user_projects\domains\base_domain1\bin\setDomainEnv.cmd.

Open it in any text editor and find following block.  Change -Xms1G -Xmx1G

if "%JAVA_VENDOR%"=="Sun" (
set WLS_MEM_ARGS_64BIT=-Xms1G -Xmx1G
set WLS_MEM_ARGS_32BIT=-Xms1G -Xmx1G
) else (
set WLS_MEM_ARGS_64BIT=-Xms1G -Xmx1G
set WLS_MEM_ARGS_32BIT=-Xms1G -Xmx1G
)

Wednesday, July 24, 2013

Install SOA suit in Linux from Windows using Reflection X

SOA suite 11g (11.1.1.2) is installed inside the middleware directory structure. Launch Reflection X software on your local workstation and export DISPLAY variable to point to your IP:0.0 before starting the installer. 

  1. Launch Reflection X tool from your workstation 
  2. Export DISPLAY variable to :0.0
  3. cmsfndev@aldapux04b $ export DISPLAY=172.25.26.91:0.0
  4. Add 64-bit JRE installed earlier to PATH
  5. asufndv2@apux206n $ export PATH=$HOME/ jdk/bin: $PATH
  6. Launch installer from Disk1
  7. asufndv2@apux206n $ ./runInstaller -jreLoc /appl/fusn/asufndv2/jdk

Sunday, March 25, 2012

Spring bean scope annotation example

Spring bean instance will be created depend on scope specified on that bean , spring container support five types of scope
  • singleton – Return a single bean instance per Spring IoC container
  • prototype – Return a new bean instance each time when requested
  • request – Return a single bean instance per HTTP request.
  • session – Return a single bean instance per HTTP session.
  • globalSession – Return a single bean instance per global HTTP session.
Spring container default scope is singleton , so you have to be careful before use bean instance . In multi-thread environment , singleton instance must be thread safe to avoid race condition . In that situation you might use prototype scope. Other three scopes are only valid in the context of a web-aware Spring ApplicationContext.
Example
Here is an example to explain difference between singleton and prototype .
1. Singleton Example: Since no bean scope is specified ,default to singleton
package com.example.springscope;

import org.springframework.stereotype.Service;

@Service("userService")
// default scope is Singleton
public class User {
 private Integer id;
 private String userName;

 public int getId() {
  return id;
 }

 public void setId(Integer id) {
  this.id = id;
 }

 public String getUserName() {
  return userName;
 }

 public void setUserName(String userName) {
  this.userName = userName;
 }
   public String toString(){
    return "[ ID : "+id+" Name :"+userName+"]";
   }
}


Configuration XML : component-scan will allow us to use annotation base bean declaration and enable auto component scan. All beans declared in com.example and its child package will be available in spring context.


 
 


Test example :
package com.example.springscope;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

 /**
  * @param args
  */
 public static void main(String[] args) {

  ApplicationContext context = new ClassPathXmlApplicationContext(
    new String[] { "app-config.xml" });
  // retrieve configured instance
  User customerA = (User) context.getBean("userService");
  customerA.setId(1);
  customerA.setUserName("Jeff");
  System.out.println(" Customer Info A:" +customerA);
   // Since Scope is singleton , same instance will be return to caller
  User customerB = (User) context.getBean("userService"); 
  System.out.println(" Customer Info B:" +customerB);
 }

}


Output :
 Customer Info A:[ ID : 1 Name :Jeff]
 Customer Info B:[ ID : 1 Name :Jeff]


In this example Id and name has been set on the customerA but same value is also showing on customerB , because of singleton scope. Spring container will create only one object for singleton scope , that will be return to caller every time.
Prototype Example
If you want new instance every time , you have to use prototype scope .
 package com.example.springscope;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

@Service("userService")
@Scope("prototype")
public class User {
 private Integer id;
 private String userName;

 public int getId() {
  return id;
 }

 public void setId(Integer id) {
  this.id = id;
 }

 public String getUserName() {
  return userName;
 }

 public void setUserName(String userName) {
  this.userName = userName;
 }
   public String toString(){
    return "[ ID : "+id+" Name :"+userName+"]";
   }
}

Test Example :
package com.example.springscope;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {

 /**
  * @param args
  */
 public static void main(String[] args) {

  ApplicationContext context = new ClassPathXmlApplicationContext(
    new String[] { "app-config.xml" });
  // retrieve configured instance
  User customerA = (User) context.getBean("userService");
  customerA.setId(1);
  customerA.setUserName("Jeff");
  System.out.println(" Customer Info A:" +customerA);
   // Since Scope is prototype , new instance will be return to caller
  User customerB = (User) context.getBean("userService"); 
  System.out.println(" Customer Info B:" +customerB);   // all fields value will be null
  
  customerB.setId(2);
  customerB.setUserName("Jhon");
  System.out.println(" Customer Info B:" +customerB);  
  
 }

}


Output :
  Customer Info A:[ ID : 1 Name :Jeff]
 Customer Info B:[ ID : null Name :null]
 Customer Info B:[ ID : 2 Name :Jhon]


You can download this example project from github https://github.com/sujanctg2005/Example