<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-4864851362075276136</id><updated>2024-09-04T05:09:32.854-07:00</updated><title type='text'>Atif ullah Baig - Java Tech Blog</title><subtitle type='html'>A blog dedicated to discuss different Java based technologies and innovative ideas.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://atifullahbaig.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4864851362075276136/posts/default?max-results=3'/><link rel='alternate' type='text/html' href='http://atifullahbaig.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/4864851362075276136/posts/default?start-index=4&amp;max-results=3'/><author><name>Atif Baig</name><uri>http://www.blogger.com/profile/05394309001905466575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7xKmj_0lRkS2ZF1ueUIkARNbzrgz2l6KbM7YFxAcq2e7h6KjnQiNN5R9ozww-CqB1D1ASBHQaAtmnFnMMMQiUWNy-j0xnIzqs3_DMd7VjFqfTtLDF6KBXi9zfHCVCpA/s1600/*'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>16</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>3</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-4864851362075276136.post-1375111178104087244</id><published>2013-08-09T00:54:00.000-07:00</published><updated>2013-08-09T02:18:39.776-07:00</updated><title type='text'>Handling cross cutting concerns with AOP - Spring AspectJ Example</title><content type='html'>&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;div dir=&quot;ltr&quot; style=&quot;text-align: left;&quot; trbidi=&quot;on&quot;&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Cross Cutting Concerns&lt;/h3&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
A cross cutting concern is a concern that is spread over multiple modules. For example logging user activities whenever any operation is performed is a cross cutting concern. To understand this lets say we have a service layer in our application and there are different services on that layer. If we want to log user activity whenever any operation is performed then we would definitely need to embed same logging code into each service class which is obviously code scattering.&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
The above issue is tackled by AOP (Aspect Oriented Programming) which removes the need for writing redundant code in our application.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
AOP (Aspect Oriented Programming)&lt;/h3&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
As the name suggests AOP is based on Aspects. Each Aspect is a module that removes the need to scatter similar code over multiple modules thus AOP modularizes the cross cutting concerns.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Core Concepts &lt;/h3&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Joinpoint:&lt;/b&gt; The point in the execution of an application where you want insert additional logic to be executed.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Pointcut:&lt;/b&gt; Expression that select one or more jointpoints.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;b&gt;Advice:&lt;/b&gt; Code that will be executed at a jointpoint that has been selected by a pointcut. Following are the types of Advice.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;1. Before Advice (this executes before joinpoint)&lt;br /&gt;
&amp;nbsp;2. After Advice (this executes after joinpoint)&lt;br /&gt;
&amp;nbsp;3. Around Advice (this executes around joinpoint)&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&amp;nbsp;&lt;b&gt;Aspect:&lt;/b&gt; Module that encapsulate pointcuts and advices.&lt;/div&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3 style=&quot;text-align: left;&quot;&gt;
Spring AspectJ Example&lt;/h3&gt;
&lt;div style=&quot;text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;b&gt;pom.xml&lt;/b&gt;

 

&lt;br /&gt;
&lt;pre&gt;&amp;lt;project xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&amp;nbsp;
xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xsi:schemalocation=&quot;http://maven.apache.org/POM/4.0.0&amp;nbsp;
http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&amp;gt;

&amp;lt;modelversion&amp;gt;4.0.0&amp;lt;/modelversion&amp;gt;
&amp;lt;groupid&amp;gt;org.atif.demo.aop&amp;lt;/groupid&amp;gt;
&amp;lt;artifactid&amp;gt;aop&amp;lt;/artifactid&amp;gt;
&amp;lt;version&amp;gt;1.0-SNAPSHOT&amp;lt;/version&amp;gt;
&amp;lt;packaging&amp;gt;jar&amp;lt;/packaging&amp;gt;
&amp;lt;name&amp;gt;aop&amp;lt;/name&amp;gt;
&amp;lt;url&amp;gt;http://maven.apache.org&amp;lt;/url&amp;gt;
&amp;lt;properties&amp;gt;
&amp;lt;project .build.sourceencoding=&quot;&quot;&amp;gt;UTF-8&amp;lt;/project&amp;gt;
&amp;lt;/properties&amp;gt;
&amp;lt;dependencies&amp;gt;      
&amp;lt;dependency&amp;gt;
&amp;lt;groupid&amp;gt;org.springframework&amp;lt;/groupid&amp;gt;
&amp;lt;artifactid&amp;gt;spring-context&amp;lt;/artifactid&amp;gt;
&amp;lt;version&amp;gt;2.5&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
&amp;lt;groupid&amp;gt;aspectj&amp;lt;/groupid&amp;gt;
&amp;lt;artifactid&amp;gt;aspectjrt&amp;lt;/artifactid&amp;gt;
&amp;lt;version&amp;gt;1.5.4&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
&amp;lt;groupid&amp;gt;cglib&amp;lt;/groupid&amp;gt;
&amp;lt;artifactid&amp;gt;cglib&amp;lt;/artifactid&amp;gt;
&amp;lt;version&amp;gt;2.2&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
&amp;lt;groupid&amp;gt;org.springframework&amp;lt;/groupid&amp;gt;
&amp;lt;artifactid&amp;gt;spring-aop&amp;lt;/artifactid&amp;gt;
&amp;lt;version&amp;gt;2.5&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
&amp;lt;groupid&amp;gt;org.aspectj&amp;lt;/groupid&amp;gt;
&amp;lt;artifactid&amp;gt;aspectjweaver&amp;lt;/artifactid&amp;gt;
&amp;lt;version&amp;gt;1.6.11&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;dependency&amp;gt;
&amp;lt;groupid&amp;gt;commons-logging&amp;lt;/groupid&amp;gt;
&amp;lt;artifactid&amp;gt;commons-logging&amp;lt;/artifactid&amp;gt;
&amp;lt;version&amp;gt;1.1.3&amp;lt;/version&amp;gt;
&amp;lt;/dependency&amp;gt; 
&amp;lt;dependency&amp;gt;
&amp;lt;groupid&amp;gt;junit&amp;lt;/groupid&amp;gt;
&amp;lt;artifactid&amp;gt;junit&amp;lt;/artifactid&amp;gt;
&amp;lt;version&amp;gt;3.8.1&amp;lt;/version&amp;gt;
&amp;lt;scope&amp;gt;test&amp;lt;/scope&amp;gt;
&amp;lt;/dependency&amp;gt;
&amp;lt;/dependencies&amp;gt;
&amp;lt;/project&amp;gt;&lt;/pre&gt;
&lt;b&gt;Operation.java&lt;/b&gt;

&lt;br /&gt;
&lt;pre&gt;package org.atif.demo.aop;

/**
 *
 * @author atif
 */
public enum Operation {
    ADD(&quot;Addition&quot;),
    EDIT(&quot;Update&quot;),
    DELETE(&quot;Delete&quot;),
    VIEW(&quot;View&quot;);
   
    private String name = null;
   
    Operation(String name) {
      this.name = name;   
    }
   
    public String getName() {
        return this.name;
    }   
}
&lt;b&gt;
&lt;/b&gt;&lt;/pre&gt;
&lt;b&gt;EventLogger.java&lt;/b&gt;

&lt;br /&gt;
&lt;pre&gt;package org.atif.demo.aop;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

/**
 * @author atif
 *
 */
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface EventLogger {Operation op();
}
&lt;b&gt;
&lt;/b&gt;&lt;/pre&gt;
&lt;b&gt;EventLoggerAspect.java&lt;/b&gt;

&lt;br /&gt;
&lt;pre&gt;package org.atif.demo.aop;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.core.Ordered;

/**
 * Simple Spring AOP aspect, intercepting every method
 * which uses the {@link EventLoggerAspect} annotation.
 *
 * Every method willing to have access checked, needs to declare
 * both the annotation and {@link EventLoggerAspect} as one of its parameters.
 *
 * @author atif
 */
@Aspect
public class EventLoggerAspect implements Ordered {
    private static Log LOG = LogFactory.getLog(EventLoggerAspect.class);
    private int order = 0;

    /**
     * Logs user operation.
     * An AspectJ annotation declares the pointcut for this aspect.
     *
     * @param joinPoint AOP object which will get automatically injected
     * @param op The EventLogger annotation as extracted from the intercepted method.
     */
    @Before(&quot;@annotation(logger)&quot;)
    public void logOperationStart(JoinPoint joinPoint, EventLogger logger) {

        Operation operation = logger.op();       

        System.out.println(&quot;About to perform &quot; + operation.getName() + &quot; operation.&quot;);
    }

    /**
     * Logs user operation.
     * An AspectJ annotation declares the pointcut for this aspect.
     *
     * @param joinPoint AOP object which will get automatically injected
     * @param op The EventLogger annotation as extracted from the intercepted method.
     */
    @After(&quot;@annotation(logger)&quot;)
    public void logOperationEnd(JoinPoint joinPoint, EventLogger logger) {

        Operation operation = logger.op();       

        System.out.println(&quot;Performed &quot; + operation.getName()+ &quot; operation.&quot;);
    }

   
    public void setOrder(int order) {
        this.order = order;
    }   
   

    @Override
    public int getOrder() {
        return order;
    }
}

&lt;/pre&gt;
&lt;b&gt;CRUDService.java&lt;/b&gt;

&lt;br /&gt;
&lt;pre&gt;package org.atif.demo.aop;

/**
 *
 * @author atif
 */
public class CRUDService {
       
    @EventLogger(op= Operation.ADD)
    public void add() {
        System.out.println(&quot;Operation in progress...&quot;);
    }
   
    @EventLogger(op= Operation.EDIT)
    public void edit() {
        System.out.println(&quot;Operation in progress...&quot;);
    }
   
    @EventLogger(op= Operation.DELETE)
    public void delete() {
        System.out.println(&quot;Operation in progress...&quot;);
    }
   
    @EventLogger(op= Operation.VIEW)
    public void select() {
        System.out.println(&quot;Operation in progress...&quot;);
    }
}

&lt;/pre&gt;
&lt;b&gt;applicationContext.xml&lt;/b&gt;

&lt;br /&gt;
&lt;pre&gt;&amp;lt;beans xmlns:aop=&quot;http://www.springframework.org/schema/aop&quot; xmlns:context=&quot;http://www.springframework.org/schema/context&quot;&amp;nbsp;
xmlns:mvc=&quot;http://www.springframework.org/schema/mvc&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; xmlns=&quot;http://www.springframework.org/schema/beans&quot;&amp;nbsp;
xsi:schemalocation=&quot;http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd&quot;&amp;gt;

&amp;lt;aop:aspectj-autoproxy&amp;gt;
&amp;lt;/aop:aspectj-autoproxy&amp;gt;

&amp;lt;context:annotation-config/&amp;gt;
&amp;lt;context:component-scan base-package=&quot;org.atif.demo.aop&quot;/&amp;gt;
&amp;lt;bean class=&quot;org.atif.demo.aop.EventLoggerAspect&quot; id=&quot;eventLoggerAspect&quot;&amp;gt;
&amp;lt;property name=&quot;order&quot; value=&quot;0&quot;&amp;gt;
&amp;lt;/property&amp;gt;
&amp;lt;/bean&amp;gt;

&amp;lt;bean class=&quot;org.atif.demo.aop.CRUDService&quot; id=&quot;crudService&quot;&amp;gt;
&amp;lt;/bean&amp;gt;
&amp;lt;/beans&amp;gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;App.java&lt;/b&gt;
&lt;br /&gt;
&lt;pre&gt;package org.atif.demo.aop;

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

/**
 * AOP Demo
 *
 */
public class App
{
    public static void main( String[] args )
    {     
        ApplicationContext applicationContext;
        applicationContext = new ClassPathXmlApplicationContext(&quot;/applicationContext.xml&quot;);
        CRUDService crudService = (CRUDService) applicationContext.getBean(&quot;crudService&quot;);       
        crudService.add();
        crudService.edit();
        crudService.delete();       
        crudService.select();
    }
}

&lt;/pre&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
.....&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
About to perform Addition operation.&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
Operation in progress...&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
Performed Addition operation.&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
About to perform Update operation.&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
Operation in progress...&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
Performed Update operation.&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
About to perform Delete operation.&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
Operation in progress...&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
Performed Delete operation.&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
About to perform View operation.&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
Operation in progress...&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
Performed View operation.&lt;/div&gt;
&lt;div style=&quot;color: blue;&quot;&gt;
BUILD SUCCESSFUL (total time: 2 seconds) &lt;/div&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4864851362075276136/posts/default/1375111178104087244'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4864851362075276136/posts/default/1375111178104087244'/><link rel='alternate' type='text/html' href='http://atifullahbaig.blogspot.com/2013/08/handling-cross-cutting-concerns-with.html' title='Handling cross cutting concerns with AOP - Spring AspectJ Example'/><author><name>Atif Baig</name><uri>http://www.blogger.com/profile/05394309001905466575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7xKmj_0lRkS2ZF1ueUIkARNbzrgz2l6KbM7YFxAcq2e7h6KjnQiNN5R9ozww-CqB1D1ASBHQaAtmnFnMMMQiUWNy-j0xnIzqs3_DMd7VjFqfTtLDF6KBXi9zfHCVCpA/s1600/*'/></author></entry><entry><id>tag:blogger.com,1999:blog-4864851362075276136.post-3083270081548328492</id><published>2013-02-10T05:20:00.001-08:00</published><updated>2013-02-13T07:37:59.926-08:00</updated><title type='text'>Should I use Servlet Container or Application Server?</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In my very first post I mentioned how tomcat server(which is a Servlet Container) can be installed and in my previous post I discussed about the deployment of EAR file inside glassfish application server along with its installation. Now I think we should put some time in understanding the difference between Servlet Containers and Applications Servers.&lt;br /&gt;
&lt;br /&gt;
Suppose we need to build a simple web application that has fairly simple UI with some basic CRUD functionalities and also transaction management and user management are not of great concern for us. In this case it will be definitely reasonable to use a Servlet Container like Apache Tomcat or Jetty. Does this example imply that we always need Application Servers for more advance features in our Java EE applications? Well it all depends on how&amp;nbsp;we design and develop our application and which features are more useful for it. &lt;br /&gt;
&lt;br /&gt;
A Servlet Container is a Web Server having a concrete implementation of the abstract Servlet API and is able to run Java Servlets. Thus Servlet Container is needed for all Servlets and JSPs that are part of web component of an application. Since application servers are also capable of running Servlets, therefore it is very obvious that every application server has a Servlet Container in it. In other words Servlet Container is a part of Application Server.&lt;br /&gt;
&lt;br /&gt;
Other than running Servlets what are the features that most Application Servers possess yet are not included in Servlet Containers? The first word that comes to mind is EJBs. As most of the Application Servers have EJB Containers therefore with EJBs in our application we can avail a numbers of enterprise services offered by the EJB Containers. But what if&amp;nbsp;we use Embeddable EJB container (OpenEJB) along with Tomcat as Servlet Container. Remember with Embeddable EJB Container we can not fully avail the true power of EJBs. Embeddable containers support only EJB 3.1 Lite which is a scaled down and lighter-weight version of EJB 3.1 that goes hand-in-hand with the Web Profile and is intended for web applications. Thus with Embeddable containers we can put EJBs inside our web module (that is packaged as WAR). &lt;br /&gt;
&lt;br /&gt;
Following snapshot shows Java EE Web Profile APIs.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD-8dN0VaU_fLnxzUOV65tFAhYmhsKukDxI8UJ6PyR2yeshrMrCUcQYb3oIGY2IGvLMaQ6aw8ShDXQWLykupL0lvlbGQam8gZCJzNFRUABx9pgIj0kDEtw3D8drnOOO6j3cZR_YuZTBto/s1600/web-profile.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD-8dN0VaU_fLnxzUOV65tFAhYmhsKukDxI8UJ6PyR2yeshrMrCUcQYb3oIGY2IGvLMaQ6aw8ShDXQWLykupL0lvlbGQam8gZCJzNFRUABx9pgIj0kDEtw3D8drnOOO6j3cZR_YuZTBto/s1600/web-profile.png&quot; height=&quot;338&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Following snapshot shows the missing features in EJB Lite.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO74w-r4l2vXzC40uz7-_eb6wdPDHRORmiaTsZAcYHGAGLVLgcOvFjgG-szdwK1NxZjv9peikMjnqtlwDt2f3oCmUkTSuJUJWK5L82QoMV3DjOvzo6r38E0A4ON7PQcxRw6pPjYUc6Wts/s1600/ejb-features.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjO74w-r4l2vXzC40uz7-_eb6wdPDHRORmiaTsZAcYHGAGLVLgcOvFjgG-szdwK1NxZjv9peikMjnqtlwDt2f3oCmUkTSuJUJWK5L82QoMV3DjOvzo6r38E0A4ON7PQcxRw6pPjYUc6Wts/s1600/ejb-features.png&quot; height=&quot;550&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
The point in our EJB discussion here is that we should definitely think of using Application Server if our application needs any feature that is not supported by EJB Lite.&lt;br /&gt;
&lt;br /&gt;
So far we have seen that an Application Server has an EJB Container along with a Servlet Container and we have already discussed briefly about the features provided by both of them. Now other features that most Application Servers possess include support for JMS, JCA, RMI, JTA etc. &lt;br /&gt;
&lt;br /&gt;
We know we can add most of the Java EE features by using standalone implementations. For instance for using JMS in Servlet Container like tomcat we can use OpenJMS as JMS provider. Now the question is why should we use Application Server at all instead of a simple Servlet Container. The main reason behind using Application Servers is to ensure the use of advance Java EE features with least complexity. Using plain Servlet Container for advance features is likely to enhance the complexity of configuration(as we might be forced to use Spring + Third party solutions for adding any new feature) in the longer run. The following table shows the tradeoffs between choosing Spring and EJB 3. (I think we should not be biased and always use the best of both technologies).&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzVWHghCMrbo_L-zNh3NOs9cpHABX33mz76cPBnaYkh5r3Iu56aP_ZLBT4oTdlBjPIdVpgQmfahMlPDcqjbrYlNzAWA3emSIkBzTTwnFI7N4-fHmjkFUi7mNjZWvNyflgQZxARI-xppOo/s1600/ejb-vs-spring.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhzVWHghCMrbo_L-zNh3NOs9cpHABX33mz76cPBnaYkh5r3Iu56aP_ZLBT4oTdlBjPIdVpgQmfahMlPDcqjbrYlNzAWA3emSIkBzTTwnFI7N4-fHmjkFUi7mNjZWvNyflgQZxARI-xppOo/s1600/ejb-vs-spring.png&quot; height=&quot;484&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
Another noticeable difference between Servlet Containers and Application Servers is that, the EAR package is only deployed on Application Servers not on plain Servlet Containers. So it is important to understand the difference between WAR and EAR packages. We all know WAR file can have multiple JARs in it while EAR file can have both JAR and WAR files. So do we only need to package multiple WARs in EAR or is there any better idea behind EAR package? In fact the main reason of EAR package is to simplify the configuration and interaction between different Java EE modules like Web, EJB and Java. Thus the EAR represents a full-fledged and mature Java EE application unlike WAR package that represents only a web application. As an EAR file might have an EJB module in it therefore it is not supported by plain Servlet Containers.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4864851362075276136/posts/default/3083270081548328492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4864851362075276136/posts/default/3083270081548328492'/><link rel='alternate' type='text/html' href='http://atifullahbaig.blogspot.com/2013/02/when-should-servlet-containers-be.html' title='Should I use Servlet Container or Application Server?'/><author><name>Atif Baig</name><uri>http://www.blogger.com/profile/05394309001905466575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7xKmj_0lRkS2ZF1ueUIkARNbzrgz2l6KbM7YFxAcq2e7h6KjnQiNN5R9ozww-CqB1D1ASBHQaAtmnFnMMMQiUWNy-j0xnIzqs3_DMd7VjFqfTtLDF6KBXi9zfHCVCpA/s1600/*'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhD-8dN0VaU_fLnxzUOV65tFAhYmhsKukDxI8UJ6PyR2yeshrMrCUcQYb3oIGY2IGvLMaQ6aw8ShDXQWLykupL0lvlbGQam8gZCJzNFRUABx9pgIj0kDEtw3D8drnOOO6j3cZR_YuZTBto/s72-c/web-profile.png" height="72" width="72"/></entry><entry><id>tag:blogger.com,1999:blog-4864851362075276136.post-434390326481343065</id><published>2013-02-09T09:57:00.001-08:00</published><updated>2013-02-09T10:21:03.468-08:00</updated><title type='text'>Deploying EAR file inside glassfish on Ubuntu Machine</title><content type='html'>&lt;br /&gt;
In this post we will go through the minimal steps required to deploy EAR file inside glassfish server on Ubuntu linux machine.&lt;br /&gt;
&lt;br /&gt;
&lt;h4&gt;
&lt;u&gt;Minimal Steps Required&lt;/u&gt;&lt;/h4&gt;
&lt;br /&gt;
1. Install Sun jdk 1.6 or higher from &lt;a href=&quot;http://www.oracle.com/technetwork/java/javase/downloads/index.html&quot;&gt;here&lt;/a&gt; if not already installed but first remove any other jdk versions if they were installed previuosly.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
2. Download and install glassfish application server with following simple commands.&lt;br /&gt;
&lt;br /&gt;
&lt;i style=&quot;background-color: #f3f3f3;&quot;&gt;wget http://download.java.net/glassfish/3.1.1/release/glassfish-3.1.1-unix.sh&lt;br /&gt;sh glassfish-3.1.1-unix.sh&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
As we can configure glassfish server after its installation therefore we can skip configuring glassfish while its installation.&lt;br /&gt;
&lt;br /&gt;
3. Create a new domain with following simple command.&lt;br /&gt;
&lt;br /&gt;
&lt;i style=&quot;background-color: #f3f3f3;&quot;&gt;asadmin create-domain –adminport 4848 –profile developer domain1&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
where 4848 is default admin port. However in my case admin port was 14889.&lt;br /&gt;
&lt;br /&gt;
4. Next set admin password with following commands (Assuming that glassfish3/bin directory is already added to the PATH variable). &lt;br /&gt;
&lt;i&gt;&lt;br /&gt;&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;asadmin --user admin&lt;/span&gt;&lt;br style=&quot;background-color: #f3f3f3;&quot; /&gt;&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;asadmin&amp;gt; change-admin-password --user admin&lt;/span&gt;&lt;br style=&quot;background-color: #f3f3f3;&quot; /&gt;&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;Enter admin password&amp;gt;[Press Enter key as default is empty value]&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;br style=&quot;background-color: #f3f3f3;&quot; /&gt;&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;Enter new admin password&amp;gt;adminpass&lt;/span&gt;&lt;br style=&quot;background-color: #f3f3f3;&quot; /&gt;&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;Enter new admin password again&amp;gt;adminpass&lt;/span&gt;&lt;br style=&quot;background-color: #f3f3f3;&quot; /&gt;&lt;span style=&quot;background-color: #f3f3f3;&quot;&gt;Command change-admin-password executed successfully.&lt;/span&gt;&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
5. Now open Glassfish Administration Console and provide the admin user credentials.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg75E25qpL02bTaFi0wX1uhheA-33oRlrzoDIZEPqDe8PrO0iM6HepimclYUo7r8x9oWibuBUv4KHRGLHseFoDxotv6KCwtG5nNm7NavmZWA_HrEjzXVbfAvlLFXpHGg2TMYNPnLBlKz9M/s1600/glassfish-admin1.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg75E25qpL02bTaFi0wX1uhheA-33oRlrzoDIZEPqDe8PrO0iM6HepimclYUo7r8x9oWibuBUv4KHRGLHseFoDxotv6KCwtG5nNm7NavmZWA_HrEjzXVbfAvlLFXpHGg2TMYNPnLBlKz9M/s1600/glassfish-admin1.png&quot; height=&quot;400&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
6. Once you sign in go to the &quot;Deploy an Application&quot; link under Deployment menu.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjArqXh2VM6NTo2K35hOrQx6Ji2m06i6mv3OImPxzZopRIM4YOvEYLp1x4mChhyphenhyphens6co61GRn3FXt3xLZWHCA3wEmOk5BEsjRRZGH6NiH7sRk5nWPlZW_ki2JUpDfI7VKF2G1IowQ8iuc2A/s1600/glassfish-admin2.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjArqXh2VM6NTo2K35hOrQx6Ji2m06i6mv3OImPxzZopRIM4YOvEYLp1x4mChhyphenhyphens6co61GRn3FXt3xLZWHCA3wEmOk5BEsjRRZGH6NiH7sRk5nWPlZW_ki2JUpDfI7VKF2G1IowQ8iuc2A/s1600/glassfish-admin2.png&quot; height=&quot;400&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
7. Now select the EAR file to be deployed and click on OK button.&lt;br /&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe_vrrwihyphenhyphenXHUTGW1qQ-W-L4l94zsbkObj5ad-vNucs_vRhI56uqL7XLCOgVZrknO6IyxT9R5xyctNl0rSsR5uJ1qWTH6LUyUyJFty7dIdppHLyDCx5R8oANlgxFZN7rXmqp8AY9dqdJM/s1600/glassfish-admin4.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhe_vrrwihyphenhyphenXHUTGW1qQ-W-L4l94zsbkObj5ad-vNucs_vRhI56uqL7XLCOgVZrknO6IyxT9R5xyctNl0rSsR5uJ1qWTH6LUyUyJFty7dIdppHLyDCx5R8oANlgxFZN7rXmqp8AY9dqdJM/s1600/glassfish-admin4.png&quot; height=&quot;400&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7SAu3RC1mJ1k6BgSZkcOBeF4gR2fBhodKTKuv90aC0tHh9flYj64UEMTWGdXsEXahanwqfeChE59oqdbikBruIHgeBHPq-CGbr7qR-Mb8unF5LB7XMGGCCZCxfbmCdj0x3Jr7HYoIZS0/s1600/glassfish-admin6.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7SAu3RC1mJ1k6BgSZkcOBeF4gR2fBhodKTKuv90aC0tHh9flYj64UEMTWGdXsEXahanwqfeChE59oqdbikBruIHgeBHPq-CGbr7qR-Mb8unF5LB7XMGGCCZCxfbmCdj0x3Jr7HYoIZS0/s1600/glassfish-admin6.png&quot; height=&quot;400&quot; width=&quot;640&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
The EAR file was successfully deployed in the last step and that can be easily tested by accessing our application from the browser. &lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjhUypWHXiwSDZe_LmF3hup56JNYKcpBGuHlzLH3XciilZUjMXP8hIbbThhH6TpVhT-0AVDh-NofjkldoaRnTn4b0ar8NwTtNyu1OCiG5S5f6jxCBUrQVa3486tHmhW_d0Tyriux_4n4xo/s1600/glassfish-admin9.png&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;br /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/4864851362075276136/posts/default/434390326481343065'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/4864851362075276136/posts/default/434390326481343065'/><link rel='alternate' type='text/html' href='http://atifullahbaig.blogspot.com/2013/02/deploying-ear-file-inside-glassfish-on.html' title='Deploying EAR file inside glassfish on Ubuntu Machine'/><author><name>Atif Baig</name><uri>http://www.blogger.com/profile/05394309001905466575</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='31' height='32' src='//blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg7xKmj_0lRkS2ZF1ueUIkARNbzrgz2l6KbM7YFxAcq2e7h6KjnQiNN5R9ozww-CqB1D1ASBHQaAtmnFnMMMQiUWNy-j0xnIzqs3_DMd7VjFqfTtLDF6KBXi9zfHCVCpA/s1600/*'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEg75E25qpL02bTaFi0wX1uhheA-33oRlrzoDIZEPqDe8PrO0iM6HepimclYUo7r8x9oWibuBUv4KHRGLHseFoDxotv6KCwtG5nNm7NavmZWA_HrEjzXVbfAvlLFXpHGg2TMYNPnLBlKz9M/s72-c/glassfish-admin1.png" height="72" width="72"/></entry></feed>