Monday 10 June 2013

Sonar for maven

It is the easiest way to configure sonar for the maven based project.

Following are the changes you need for analyzing code using sonar.

1> Create a database for the sonar like "sonar"

2>Make a new entry into the setting.xml into the .m2 directory.

<profiles>
        <profile>
            <id>sonar</id>
            <activation>
                <activeByDefault>true</activeByDefault>
            </activation>
            <properties>
                <!-- EXAMPLE FOR MYSQL -->
                <sonar.jdbc.url>
                  jdbc:mysql://localhost:3306/sonar?useUnicode=true&amp;characterEncoding=utf8
                </sonar.jdbc.url>
                <sonar.jdbc.driverClassName>com.mysql.jdbc.Driver</sonar.jdbc.driverClassName>
                <sonar.jdbc.username>root</sonar.jdbc.username>
                <sonar.jdbc.password>root</sonar.jdbc.password>
                <sonar.host.url>
                  http://localhost:9000
                </sonar.host.url>
            </properties>
        </profile>
     </profiles>


3> Start the server again.
4> Now execute the command mvn sonar:sonar and hit "localhost:9000" from browser.
5> It's ready for the code analsis.

Please provide me comments if I have missed any thing to make it more helpful.




Friday 19 April 2013

Use of bean shell in liferay.


In the control panel -server-serveradministrator we have various tabs. In this tabs we have scripts.
In this we have various languages in the drop down. One language is bean shell.

It is used to execute the the java code directl. Like we want to get all the users or want to update user information we can do directly by bean shell.

Example: From the code snippet we are getting the user first name directly.

Maven based portlet in liferay.


Hi All,

Here we have a first example to make a maven based portlet in liferay. To make a maven based portlet first we need to configure maven.

1> Install the maven into your system

2> Set the System variable MAVEN_HOME like C:\Program Files\apache-maven-2.2.1

3> Add the path of the bin folder in to the Path into the system variable.  %MAVEN_HOME%\bin;

4> Now we need to make a maven repository where all the dependencies jar will be saved.To make this need to make a repository folder and need to give path of that folder into the c:/.m2/settings.xml

1:   <?xml version="1.0"?>  
2:      <settings>  
3:        <localRepository>D:/maven</localRepository>  
4:      </settings>  

   Here mention the central repository where all dependencies jar will be exist.

    In some case the .ms folder doesn,t exist you need to make it in the user folder using following folder

    md c:\Users\aalap.desai\.m2

5> Now mvn instalation has been completed now make a maven base portlet.

6>Form command prompt execute the command :mvn archetype:generate
    On the command prompt get the archtype for maven.

     

7> Select the option which kind of the liferay plugin package need to make.  Here we have a option to         make  hook,portlet,portlet with service builder etc.

8> Lets take a example to make a portlet have a use of service builder. For this we need to select the option           57.
9> It will ask for the version of the liferay you want to make the portet. Example: 6.1.20 I have selected 4
    then it will ask for the groupId,artifactId,snapshot-version.
10> After that it will     ask for conformation. Once you have confirm it will the folder with the name maven which has two folder one is maven-portlet and another is maven-portlet-service

11> In this manually need to amke the entry of

    abvoe the</projet> tag.

12> In maven-portlet src > main > webapps > web-inf > service.xml

13> Make the entity change you want to make you can make and execute the command -->> mvn liferay:build service.
    All the appropriate classes will be generated

14> Attached a sample maven portlet.
Maven sample portlet


Please let me know if any help is needed. Please let me know if I have missed anything.  

Thursday 14 March 2013

Migrate from ant to maven portlet.

1> First of all execute the command : mvn archetype:generate
    When execute this command the option comes to select which kind of the liferay plugin want to make. For example i want to make a service builder then the option withe in value liferay-service then while structure will be generated. In the option we have various option to make maven based hook,ext,portlets.

2> run the command : mvn eclipse:eclise
This will make the code into the project so we can directly import the code into the eclipse.

3> In the ant base portlet we have portlet structure as following.
bookmark-portlet
 |_ docroot
       |_css
       |_js
       |_jsp
       |_meta-inf
       |_web-inf
                |_lib
            |_src
            |_liferay-display.xml
            |_liferay-hook.xml
            |_liferay-plugin-package.properties
            |_liferay-portlet.xml
            |_portlet.xml
            |_web.xml

 |_ build.xml

 For the maven portlet we have following structure.

bookmark-portlet
 |_src
      |_main
            |_java (our java code comes here)
        |_ resource(our property files should come here)        
        |_web-apps
                  |_css
              |_js
              |_jsp
              |_web-inf
                        |_liferay-display.xml
                    |_liferay-hook.xml
                |_liferay-plugin-package.properties
                |_liferay-portlet.xml
                |_portlet.xml
                |_web.xml

For migration from ant portlet to the maven portlet put the all the java classes in to the main.java class. Put al the propertiesis and file of the meta-inf into the resource.


for the service buildes two folders has been generated like

bookmark
     |_bookmark-portlet(All the portlet related classes)
     |_bookmark-service-portlet(All the classes generated by the service builder.)
 |_pom.xml    

4> After doing this run the command mvn clean install it will meke the war into the target folder of the respective portlet. Take a portlet put it into the deploy folder of the tomcat.