Thursday 16 May 2013

Create a simple JSR 286 Portlet using Maven, Eclipse IDE, MySql - Part 1

The Portlet we are going to create can be run on any Portal Server. I have used Liferay Community Edition since its available for free.

The tools we are going to use are:

1. Java V 1.5 and above.
2. Maven: It makes life so much easier.
3. Eclipse IDE
4. MySQL database
5. Liferay Community Edition bundled with Tomcat: Latest version is available at liferay.com



Basic Setup:

  1. Install Java JDK 7: http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.htmlSet the JAVA_HOME environment variable.Update the path environment variable. Add ;%JAVA_HOME%\bin; at the end.
  2. Download Apache Maven: http://maven.apache.org/docs/3.0.5/release-notes.html
  3. Unzip it at a convenient location. Lets say C:\development\maven
  4. Add another Environment variable MAVEN_HOME with the above location.
  5. Again update path environment variable. Add ;%MAVEN_HOME%\bin; at the end.
  6. Go to windows console using cmd. Type mvn -version to check if it works.
  7. Next download Eclipse. I usually use Eclipse IDE for Java EE Developers. URL: http://www.eclipse.org/downloads/
  8. Once download is complete extract eclipse at a convenient location like C:\development\eclipse
  9. Now install Maven plugin for eclipse. Just go to help->install new software, in eclipse.
  10. Use the following update site: http://download.eclipse.org/technology/m2e/releases
  11. Now from eclipse navigate to window->preferences->maven->installations and add the maven location you just extracted.
Portal Server: I prefer Liferay Portal's Community edition since its free and has lot of features.

To download Liferay go to the following website and download there tomcat bundle. http://www.liferay.com/downloads/liferay-portal/available-releases
Liferay uses hypersonic database by default.

I prefer MySQL database since its free and pretty good. You will need MySQL server and workbench. Both can be installed from the MySQL website.

When you will start Liferay for the first time it will ask for database configuration. You can either configure database then or you can place a properties file under the root directory where you extracted the bundle.

Liferay creates a properties file by default when you configure database at startup. If it doesn't you can create a portal-setup-wizard.properties with following content:

jdbc.default.driverClassName=com.mysql.jdbc.Driver
jdbc.default.url=jdbc:mysql://localhost/lportal?useUnicode=true&characterEncoding=UTF-8&useFastDateParsing=false
jdbc.default.username=root
jdbc.default.password=root

If you are working with the latest version of MySQL and Liferay bundle you might see database related exceptions on startup.
To resolve these just download mysql-connector-java-5.1.25 and place it in tomcat/lib/ext folder.

Next we will look at how to create our first Portlet.

1 comment:

  1. Wow, marvelous blog format! How long have you been blogging for? you make running a blog glance easy. The total glance of your website is excellent, let alone the content material!
    Create a MySQL database.

    ReplyDelete