Sunday, 10 January 2016

Liferay : Solution : Possible errors while installing Maven with Liferay.

Hello,

During the installation of Maven with Liferay, I have faced numerous errors, documentation for Maven installation given by Liferay is good but I did not find any solution for below errors, here I would like to share solutions of following errors.

Here, You can find steps for installation of Maven with Liferay, this documentation is for 6.1 EE version but it will still work for Liferay 6.2 EE and CE.

Environment details :
  • Window 10. 
  • Liferay 6.2 SP14 + Tomcat-7.0.62.
  • Liferay-portal-maven-6.2-ee-sp14,
  • Apache-maven-3.3.9.
  • Local M2 repository. 

As per Liferay documentation we just need just execute "ant install" command from Liferay-portal-maven-6.2-ee-sp14, it will install all artifacts of Liferay to your local repository, while execute these command I have faced three problems one after another, lets go through the solution of each one of them.

Error  1 : Property lp.maven.repository.url or lp.maven.repository.id  was circularly defined

Error 1 : Property lp.maven.repository.url or lp.maven.repository.id  was circularly defined.



Solution for Error 1 : I need these artifacts inside my local repository so I do not need to create build.<username>.properties file, reason of this error is cause value of lp.maven.repository.id and lp.maven.repository.url properties in build.properties file.

build.properties : (this is what by default comes)

gpg.keyname=
gpg.passphrase=
lp.maven.repository.id=${lp.maven.repository.id}
lp.maven.repository.url=${lp.maven.repository.url}
lp.version.maven=6.2.10.15

build.properties : (this is what you need to change, just remove value)

gpg.keyname=
gpg.passphrase=
lp.maven.repository.id=
lp.maven.repository.url=
lp.version.maven=6.2.10.15

Error 2 : Execute failed: java.io.IOException: Cannot run program "mvn.bat": CreateProcess error=2, The system cannot find the file specified

Error 2 : Cannot run mvn.bat

Solution for Error 2:

it seems that apache mvn.bat is renamed to mvn.cmd with maven 3.3.1 version onward (Check), that means if you extract zip file of apache-maven-3.3.9, you will find following structure inside the bin folder,in order to resolve this you need to rename mvn.cmd to mvn.bat file


NO .bat FILE EXIST

Error 3   :  M2_HOME is set to invalid directory.

Error 3   :  M2_HOME is set to invalid directory.


Solution for Error 3:

So while resolving Error 2 we renamed mvn.cmd to mvn.bat that means we dont have any mvn.cmd available inside the "/bin" folder but some of the file are still expect mvn.cmd inside "/bin" folder which means we need to create a copy and make sure that we will be have two files mvn.bat and mvn.cmd inside "/bin" folder as shown below 
(Note : Both are the same files just name are different as they are expecting mvn.cmd inside some script)















Hope this will helpful to other and save some time.

Feel free to drop a question or comment.

Thanks,
Sagar Vyas



Tuesday, 15 December 2015

Liferay 7 - First look with basic explanation


Hello,

Today, first time I started Liferay 7 in my machine so thought to share basic walk through with Liferay 7 portal, in this walk through I have covered different sections of Liferay 7, play with couple of component like Blogs, Page, Document and Media,Control Panel, Mobile preview etc , Enjoy video !!

What version I have used in this video ? It is Lifeay 7 Alpha-2 Community Version

Where to download ? Well, I got it from Liferay team in Liferay Symposium workshop but I am sure you will find all latest LR7 community version here.

New features in Liferay 7, 
(Note : Trying to highlight as much as I know, there must be more than these for sure  )
  • Technically Liferay 7 has lot of new things like Micro services (Modularity) 
    • Means no more need of portlet.xml , liferay-portlet.xml etc
    • Everything is decoupled
  • Look and feel brand new (Please refer video)
  • Change in site template 
  • Configuration of navigation 
  • Create content is more easy with alloy editors 
  • Different view facilities like List, Descriptive, Icon view.
  • New localize language search
  • Approval workflow subscription base on folders
  • Geolocation content creation 
  • Blog experience is improved (Please refer video) 
  • End user interaction is improved like you can refer person with "@" annotation in comment section.
    • Ex. @Sagar Vyas
  • Document and Media library 
              Basic walk through of Liferay7 with brief description on each component.



Have a happy learning !!

Thanks,
Sagar Vyas

Monday, 14 December 2015

Java : Overriding and Overloading Concepts and Difference.

Hello friends, I know overloading/overriding are one of the famous OOB concepts that everyone knows JBut I feel more often people got confuse in this concepts.

Please go through the below diagram that will give you broad picture and lets understand point by point.




Overriding:

  • Overriding is runtime polymorphism
  • Happens in different class and Use in Inheritance : Overriding is concept that use in Inheritance where super class and sub class has same method name and same arguments
           Ex.
class Animal {
     public void myOverRiding ()
     {
      System.out.println("This is animal overriding ");
     }
}

class Horse extends Animal {
     public void myOverRiding ()
     {
      System.out.println("This is horse overriding ");
     }
}
  • Can we prevent overriding?
o   “Final” keyword can be prevent class to be inherited that means technically we are preventing overriding.
o   It will throw following compile time error.


  •  JVM decides what to do at run time: when you are calling any method with help of sub/super class object, JVM decides at run time that method of which class needs to be called
      public class UserAnimal {
     public static void main(String s[])
     {
           Animal aniHrnew Horse(); //Line 4
           aniHr.myOverRiding();
   //In overriding it will call actual object class method.
     }
}

class Animal {
     public void myOverRiding ()
     {
           System.out.println("This is animal overriding ");
     }
}
class Horse extends Animal {
    
public void myOverRiding ()
     {
          System.out.println("This is horse overriding ");
     }
}

                                In above example we have two classes Animal – Super class and Horse – Sub class which shares same method called myOverRiding() now in UserAnimal class we have created an object of Horse and reference of Animal (refer Line # 4) and we called myOverRiding() method with help of that object (aniHr) now question is, which class’s method myOverRiding() will be called ? Any guess?

     Answer, in overriding JVM runtime use actual object and in overloading JVM use reference (Animal) instead of actual object (Horse)


O/P:  This is horse overriding

Overloading:

  • Overloading is compile time polymorphism
  • Happens in same class only
  • Method can have same name and different arguments
   class Animal { 
   MyStuff() {  System.out.println("Hi Cow");  }
   MyStuff(int i) { System.out.println("Hi Dog");  }
  }

  • Can we prevent override? Unlike override prevent with final keyword with class , java don’t have anything to prevent overload in class (unless you wish to not write same method name J )
  • JVM decides everything at compile time : which class method needs to be called that will decide at compile time (in overloading JVM use reference (Animal) instead of actual object (Horse))
  • If you try to write same method with same arguments it will throw compile time error.
Ex.  This is the similar example which I have explained above just o/p is different

public class UserAnimal {
     public void doStuff(Animal a)
     {
           System.out.println("This is animal ");
     }
     public void doStuff(Horse a)
     {
           System.out.println("This is horse");
     }
     public static void main(String s[])
     {
           UserAnimal obj = new UserAnimal();
           Animal aniHrnew Horse();
           obj.doStuff(aniHr)
       //In overloading it will call reference class method.
     }
}
class Animal {
}
class Horse extends Animal {
}

O/P: This is animal

Hope this article would be value added and helpful, have a happy learning J

Thanks,
Sagar Vyas

Wednesday, 30 April 2014

Liferay : How to apply patch in Lifeary?

Hi there,

This very common requirement when we need to install Liferay patch to our server, usually Lifeary team is provide steps along with patch but in case if you don't have it you can follow below mentioned steps.

Following are the steps for install patch in Liferay, Please go through it step by steps.

Here PATCHING_TOOL_HOME = Path to the “patching-tool” directory in your tomcat.

How to do it ?
  • Stop Tomcat.
  • Place the patch(.zip file) in the PATCHING_TOOL_HOME/patches/ directory.
  • Open command prompt.
  • Go to PATCHING_TOOL_HOME directory.
  • Give command “patching-tool auto-discovery” for Windows and “./patching-tool.sh auto-discovery” for Linux.
  • Check that default.properties file will be created in PATCHING_TOOL_HOME
    directory.
  • Give command “patching-tool install” for Windows and “./patching-tool.sh install” for Linux.
  • Patches will be installed successfully and you will get appropriate message for that.
  • Give command “patching-tool info” for Windows and “./patching-tool info” for Linux to know installed patches.
  • Start Tomcat.

Note:- 
For each patch you should have proper patching-tool version otherwise you might face error like
"The 'hotfix-440' patch's patching tool version number is higher than the patching tool version number: 2 > 1"

Where you get it ?

  • Login with authorized person credential in lifreray.com
  • Go to Places(right corner) > Customer portal > Downloads > Liferay Portal > All Downloads(Patches) > Select version + All patches in Filter type and download appropriate patching-tool zip.
Hope this help.

Thanks,
Sagar Vyas


Friday, 25 April 2014

Spring : First step in Spring Framewrok

Hello Friends,

This blog help us to understand basic feature and may give you an answer of question “Why I should use Spring framework in my development?”.

History: Friends when you start learning any new thing, I would say start with the history and purpose of it.
  • Rod Johnson is father of this framework,He has realised on June 2003.
  • V 1.0 in March 2004
  • V 2.0 in October 2006
  • V 3.0 in December 2009
  • V 4.0 in December 2013
I am presenting a Fantastic Four reasons/features with brief understanding of Spring framework.

1. Dependency injection or Inversion of Control.[ICO and DI]  
"Don't worry about create an instance just ask me whenever you require it,another words It says do not need to create an object of a class into another class."
  Ex.
          class A {
             function()
               {
                 B bObj = New B();
              }
            }
  • Class A is completely depend on Class B : Modification of Class B may force you to modify Class A.
    Ex. Change in name of methods or class name itself.
  • This is a simple example but in real time it may me much more complex then it looks.
  • To overcome with this problem,Spring came up with Dependency injection, with help of Spring-config.xml you can easily and effectively resolve this problem.

2.Aspect Oriented Programming :[AOP]
"It says do not mix business logic with non-business logic"
      Ex.
                      class FindNumber {
                          // logger
                               try{
                                   function callMe(a,b,c)
                                    {
                                       return a*b+c;
                                    }
                                   }
                               catch(Exception e)
                                  {
                                     //logger.error
                                  }
                                  //logger.info

                               }
    • Main purpose of this class is to find a number, but you can see there are lot of other things surrounding it, like logger, Exception handling etc..
    • We are simply mixing two things. [Functional + Non functional], we may increase our difficulty to mange our class in future.
    • It's not only logger we used to mix with our program but in real time there will be more like transaction management, cashing management etc and We will end up with a very confusing class which has plenty of line containing Non-functional as well functional. 
    • AOP help us to overcome this problem which provides the solution which help us to keep non functional things out side the class.
    3.Data access [JDBC,ORM,OXM,JMS,Transaction management]
    • Spring JDBC : If you are using Spring JDBC then you do not need to panic about following code.
             - Opening and Closing database connection.
             - Any exception handling code.
             - Prepare and execute statement and result set.
    • Spring ORM : [Spring Object Relational Mapping]

        - Provide full API support to integrate ORM tool like Hibernate, JPA etc.

    • Spring OXM :
            - Converting Java Object to XML and Vice Versa.
            - Fully support to integrate with JAXB, Castor etc..
    • Spring JMS: Java Message Services.
            -Provide support to produce and consume message.

    • Spring Transaction Management.
          - The Spring Framework provides both declarative and           programmatic transaction management. Most users prefer       declarative transaction management, which is                 recommended in most cases.
          - You write your code once, and it can benefit from             different transaction management strategies in               different environments.
    4.Spring MVC
          - Provide Complete MVC structure, Highly recommended in         web designing and development.
          - The Spring Web model-view-controller (MVC) framework         is designed around a DispatcherServlet that dispatches       requests to handlers, with configurable handler               mappings    
          - The default handler is based on the @Controller and          @RequestMapping annotations, offering a wide range of         flexible handling methods.




      Hope this will help you guys to understand spring at first look.

      Let me know in case of any questions/queries.

    Thanks,
    Sagar Vyas


    Saturday, 14 September 2013

    Liferay : Tag cloud OOB integration with custom MVC portlet

    Hi There,

    Hope you are doing good.
    In “Hi I am Liferay” we have seen last two things which might be small but equaly important for Liferay developer.

    1. Next we will see how to integrate tag portlet [OOB portlet] with any custom portlet. [Liferay 6.1]


    Requirement description : I have my own custom MVC portlet called fruit portlet which will describe all fruit characteristics and items which made from it, which will be filter base on tag, when user will click on any tag for example an apple all entries which tagged as an apple will display along with description,and only those tags should be display on the page which are associated with custom entity.


    Solution :
    Step 1) As Tag [Tag cloud or Tag navigation] portlet is different entity we need to work on IPC so when user click on any tag your portlet[custom portlet] should know at time of render page.
    To accomplish it you need to do certain things as below.
    In portlet.xml of your portlet you need to have following entries.
    <portlet-app  ........>
    <portlet>
     <portlet-name>Fruit</portlet-name>
     <display-name>This is fruit decstiption</display-name>
                           |
                           |

     <supported-public-render-parameter>tag</supported-public-render-parameter>

    </portlet> 

    <public-render-parameter>
       <identifier>tag</identifier>
       <qname xmlns:x="http://www.liferay.com/public-render-parameters">x:tag</qname>
    </public-render-parameter> 

    </portlet-app  ........>

    Step 2) In JSP of your portlet where you want to display tags related to your entity you need to write following code.


     <liferay-ui:asset-tags-navigation
        classNameId="<%= classNameId %>"
        displayStyle="<%= displayStyle %>"
        hidePortletWhenEmpty="<%= true %>"
        maxAssetTags="<%= maxAssetTags %>"
        showAssetCount="<%= showAssetCount %>"
        showZeroAssetCount="<%= showZeroAssetCount %>"
    />



    Where
    1.classNameId (long) = your entity class name id for which you need to display tags, in our case we will get it as below 

    long clssNameId = com.liferay.portal.util.PortalUtil.getClassNameId(FruitEntry.class.getName());
     
    2.displayStyle (String) = We will give here "cloud" as we want tag cloud look rather navigation.
    
    
    3.hidePortletWhenEmpty (Boolean)= if true it will hide portlet when there is no related tags found 
    
    
    4.maxAssetTags (int) =  number of tags to be displayed on the page.
    
    
    5.showAssetCount (Boolean) =  true 
     
    6.showZeroAssetCount (Bollean) = false
    
    
     
    Step 3) In controller class in doView() method of portlet every time you need to check as follow.
     

    String tagName = renderRequest.getParameter("tag");

    when user click on any tag [on tag cloud portlet] you will get tag name in doView() 
    as tagName as shown in code above, now you can right some code which will bring list of assets
    which is associated with clicked tag.
    
    
    Hope this helps.
    
    
    For more information you can contact on sagar.vyas.blogspot@gmail.com
    
    
    Thanks,
    Sagar Vyas 

    Saturday, 7 September 2013

    Liferay : Solution: Problem to remember Current Tab liferay-ui:tabs while performing action/render on jsp ?



    Hi,
             

                          Many of us are using <liferay-ui:tabs ..> </ liferay-ui:tabs> and there are good road map given in Liferay’s site too in shape of blogs and forums, but one question is frequently asked by people that “How to persist current tab ? or How to remember current tab even though page gets refresh ? all are these open question ”


    This is basic question but no clear answer given anywhere.

    I would to provide neat and clean explanation for same.

    Scenario:
    1.  I have view1, view2 and view3 which includes in master.jsp and one controller called MyController.java [JSR-286] portlet which extends MVCPortlet class of Liferay.
    2.  I have used following code in my master.jsp

    <%
     PortletURL portletURL = renderResponse.createRenderURL();
     String currTAB = ParamUtil.getString(request, "currTAB", tabs1);
     portletURL.setParameter("currTAB", currTAB);
     %>
    <liferay-ui:tabs param="currTAB"  names="Tab1,Tab2,Tab3"   refresh="<%= true %>" url="<%=portletURL.toString() %>">

    <liferay-ui:section >
       <%@ includefile="/jsp/view1.jsp" %>
    </liferay-ui:section>

    <liferay-ui:section>
    <%@ include file="="/jsp/view2.jsp " %>
    </liferay-ui:section>

    <liferay-ui:section>
    <%@ include file="="/jsp/view3.jsp " %>
    </liferay-ui:section>

    </liferay-ui:tabs>
     

    Problem:


    Suppose you are on view2.jsp and there you are submitting a form [or in other words your refreshing a current page which is view2.jsp] and you will be redirected to default page [in our case it is view1.jsp], it should not happened cause you have performed an action on view2.jsp page you suppose to rendered to view2.jsp instead of view1.jsp


    Root cause: 

    When you refresh the page by actionURL or renderURL your client that means your browser does not know where you were earlier other words on which tab? So it will be redirecting to default page which is view1.jsp in our case.
     

    How to resolve this?

    So we know root cause now question is how to tell browser current tab? An obvious answer is keep live one parameter in each URL which will always tell to your browser that where to redirect.


    How to achieve this?

    As you might have observed ”currTAB” parameter in <liferay-ui:tabs>  which will help you to achieve this, when you click on either of tab value of “currTAB” is automatically maintain accordingly. For ex. When user click on 3rd tab which name is “Tab3” it automatically store currTAB=”Tab3” as parameter in url.

    Now you just need to maintain this variable. Like as below,

    String currTAB = ParamUtil.getString(request, "currTAB", “Tab1”);
     portletURL.setParameter("currTAB", currTAB);
        
         What does above code says “It will try to get currTAB variable and if it is not found the same it will pass Tab1 as parameter value”

         You need to write above code at everywhere you require maintaining tab value.

         Make sure you keep refresh="<%= true %>" otherwise page will be not refreshed.

    Hope this helps.

    In case of more information require you can contact on

    Thanks,
    Sagar Vyas