Saturday, 26 January 2013

Basic introduction and usage of log4j

Log4j is used to log the data in a format that will be understandable and useful. Here is the documentation. 

I am going to explain how to start a simple logger using log4j for you project with a basic example. 

Download the file from Apache log4j.
  1. Create a project. (I have created a java project).
  2. Create a file with name it can be log4j.xml also). 
  3. If it is a java project, copy properties file into src folder.
  4. If it is a web project then copy this project under WEB-INF/classes
  5. Add following entries to the file. (You can add more entries, see. Documentation)
# Root logger option
log4j.rootLogger=INFO, file, stdout

# Direct log messages to a log file
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

# Direct log messages to stdout(console)
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

Run your project now and check your log file/ console.....

Saturday, 19 January 2013

How To Disable Automatic Updates By Service.xml with Database in Liferay

Even though liferay service layer is an excellent and efficient tool to work with database and it generates automatic hibernate spring framework, it has some drawback in terms of customization. model-hints.

portlet-model-hints.xml and portlet-model-hints-ext.xml entries are work around for customizing database schema. Still if you face any problem and want to continue without liferay service layer database scheme, you can just disable this update with database.

  1. Add in resource folder(If you are not using maven, then locate the path of and keep extension file in the same path.)
  2. Enter following entry and restart the server. 

How To Refresh Page From Vaadin Application

We can refresh webpage from vaadin using javascript. Try following code snippet to reload webpage.


Liferay-Maven: Installation For Beginners

1. Install maven(I have used 3.0 ) and set path for M2_HOME, if you don't know how to install maven, check my previous post here)

2. Take a backup of .m2 and copy whole folder in <documents and settings>/<User>/.m2 folder

3.  Open command prompt( Preferably open liferay SDK folder in command prompt) and type the following instructions

    -> mvn archetype:generate
    -> Select appropriate number for liferay-portlet-archetype(in 3.0 version it is 45)
    -> Enter groupID :
    -> artifactId     : etransform-portlet
4. It will create a folder structure with artificatID consisting of src folder and pom.xml. (Replace them with your src folder and pom.xml, if  you have already src file and your customized pom.xml).

5. goto artifact(Here etransform-portlet) and run following instruction
    -> mvn -o package
    It creates target folder and packaged structure

6. mvn clean liferay:deploy to deploy liferay libraries in to portlet.

7. Other liferay maven commands
    mvn liferay:deploy
    mvn liferay:build-lang
    mvn liferay:build-wsdd
    mvn liferay:build-thumbnail   
    mvn liferay:theme-merge
    mvn liferay:build-css
    mvn liferay:build-db
    mvn liferay:build-service
    mvn liferay:direct-deploy   
    mvn liferay:build-ext

8. Other maven commands
    mvn clean    - will delete target directory
    mvn validate    - validate whether project is correct and necessary information is available
    mvn compile    - compile source code and place classes in target/classes folder
    mvn test    - run tests using a suitable unit testing framework
    mvn package    - take the compile code and package it in distributabel format(WAR/JAR as metioned in pom.xml)
    mvn verify    - run any checks to verify the package is valid and meets quality criteria
    mvn install    - install the package into the local repository, for use as a dependency in other projects locally
    mvn deploy    - done in an integration or release environment, copies the final package to the remote repository for sharing with other developers and projects
9. maven eclipse commands
    mvn eclipse:eclipse           
        - create metainformation: meta files for eclipse are created, can be used for project import
    mvn -Dwtpversion=2.0 eclipse:eclipse   
        - create metainformation with wtp: same like create metainformation + WTP plugin infos(To convert into eclipse web project)
    mvn -Declipse.workspace=/path/to/workspace eclipse:add-maven-repo
        - tell eclipse where local repository is located
10. maven release project
    mvn release:prepare
        - prepare release: informations about versions number are collected
    mvn release:clean
        - clean release: rollback to snapshot versions
    mvn release:perform
        - perform release: deploy project to remote repository and make tag in version control system.
            username and password for version control system are taken from server informations in
            ~/.m2/settings.xml. serverID is same like defined in deploymentServer ... this behaviour is not whished
    mvn release:perform -Dusername=foo -Dpassword=bar
        - perform release with username and password for authentication on version control system


    mvn deploy:deploy-file -Dfile=/path/to/jar/file -DrepositoryId=repos-server -Durl= -DgroupId=javax -DartifactId=mail -Dpackaging=jar-Dversion=1.0.1

11. maven tomcat integration(You need to enter tomcat manger ID in pom.xml).
    mvn tomcat:deploy
    mvn tomcat:redeploy
    mvn tomcat:undeploy
    mvn tomcat:stop
    mvn tomcat:start

Friday, 18 January 2013

Maven: Installation For Beginners

 Follow steps 1 to 4 to create a sample web project using maven.
  Download apache maven here.
  1.  Set path for maven till /bin and JAVA_HOME/bin.
  2.  To test maven is properly configured or not, open command prompt, type mvn --version it will show the path variable.
  3. Type following instruction at the command prompt (Replace groupID with your package structure and artificatID with your projectname).
mvn archetype:generate -DgroupId=com.test -DartifactId=sampleWebApp -Dversion=1.0-SNAPSHOT -DarchetypeArtifactId=maven-archetype-webapp -DinteractiveMode=false

Tuesday, 15 January 2013

Creating WebService Using Liferay Service.xml

Steps to create webservice using liferay service.xml

1. Add remote-service="true" in service.xml for the perticular entity.
<entity name="Customer" local-service="true" remote-service="true" cache-enabled="false">

2. Build service. It will create <entityName> file in XXX.portal.service.impl
    eg: in com.test.portal.service.impl.
3. Create a method in <entityName> and return some value.
    eg: extends CustomerServiceBaseImpl{
               public String getCustomerName(String customerName){
                //TO DO, Write your logic here and based on logic return your details   
                return customerName;

4. Build service and web-service. It will create required classes. You can check your project entry in WEB-INF/server-config.wsdd.
        <parameter name="allowedMethods" value="getSquareOf"/>
5. Check whether your web service is running fine or not by checking wsdl file.

Steps to validate webservice

6. Use service definition given in step 5 and create a webservice client.
7. Use any webservice testing tool to validate webservice.

Saturday, 12 January 2013

Jboss: Connect To Server From Remote Client

Use following command to allow all the clients(Any IP) to access your Jboss server.

Open %JBOSS_HOME% /bin in command prompt and type

run --host -b

Another simple technique can be to create a batch file for this.

Open a text file, type following entry

@Echo off
call %JBOSS_HOME%/bin/run.bat --host

Save it as sameText.bat(Where ever you want) and click on it. 

Liferay: Unable To Communicate With Repository

Generally, we(Software Developers) ignore exceptions, but when it comes to production, people are particular about each and every exception, even though it is ignorable, people need explanation to ignore it.

Recently one thing happened to me while using liferay. They use proxy servers in their production servers, hence people are getting following exception.  

Unable to communicate with repository

Even though it is ignorable, they don't want this exception in their log files. 

Following entry in does the trick. 
(Keep the values black) . 

And restart the server, then this exception will never appear in log files. 

Eclipse: Cannot Find The Class Problem

Recently I have faced Cannot find the class problem in eclipse. I remember my project worked fine last month. Suddenly it is crying to locate some java classes when I compile this project. Still interesting this is that, those classes are there in the mentioned package. Even googling didn't help me.

Finally I found a work around.

Simple, I copied whole class file into new java class file, deleted the original java class file and renamed the new class name to older java class name.

It worked well for me, if you face similar problem try this small tip, it may works.

Weird things happen in eclipse some times....

Allow All WebSerice Clients To Use Liferay Webservice

As we know, there is an entry that we need to enter into to access webservice from the client.


But if we want to allow every client to use these webservices created by liferay i.e. if we don't want any restriction to access liferay webservice then keep the entry blank in