Archive

Posts Tagged ‘Java/Java EE’

How-To Deploy Roller 4 on GlassFish V3

December 10, 2009 7 comments

I’ve just started blogging seriously. Many free blogging tool providers are available. Widely known are the WordPress and Blogger. For some reasons, I decided to use WordPress as my main blogging tool.

I’ve given some thoughts to start developing a Web-based Blogging Tool just to have some hands-on experience on the Web Development and Design process. Besides, as I advocate the Open Source Community I would like to make a humble contribution to this great community.

I was wondering which platform on which I should rely to start developing this project. From my notice, most web applications nowadays are developed in PHP. PHP has been used very widely by the public. Well, PHP is a very cool scripting language and I’ve always looked forward to learning it. But, as it is a top priority to my career path is to have a solid development background using Java/J2EE technology, I’ve decided to start a project for developing a Java Web-based Blogging Application. Fortunately, somebody already started developing such a project long time ago, since 2002. This application is sponsored by Apache Software Foundation and is called Roller Weblogger.

So, trying to make Roller up and running, we need to download a Java Web Server to be the deploying environment for Roller. You can download Tomcat and use it as a Web Server to deploy Roller. Refer to this Installation Guide to deploy Roller on Tomcat.

In my case, I decided to use GlassfishV3 due to the features and frameworks bundled with. Here, I’ll explain step by step how to install GlassfishV3, deploy Roller on it, and avoid a possible problem that might hinder the deployment process!

So, let’s start!

STEP 1: GlassfishV3

STEP 1.1: Download GlassfishV3

Download GlassFishV3 Prelude or Preview. Compare between them here.

Refer to Comment#:1

STEP 1.2: Install/Configure GlassfishV3

Install GlassfishV3 by simply running the script. It is not a big deal just follow the instructions!

STEP 1.3: Start GlassfishV3

Go to where Glassfish binary files are:

cd $GF_HOME/glassfish/bin
  • To start the domain:
    ./asadmin start-domain
  • To stop the domain:
    ./asadmin stop-domain

Or alternatively, I prefer to start/stop the server by running these: “log will be output to the screen, so you can monitor it

  • To start the server:
    ./startserv
  • To stop server:
    ./stopserv

Now, you can reach the Admin Console at:

For further details, have a look at the GlassfishV3 Quick Start Guide!

STEP 2: MySQL JDBC Connection

STEP 2.1: Download Connector/J

You will need to download the MySQL JDBC Connector to allow Roller interact with the MySQL Database Server. Here, I used the MySQL Connector/J 5.1.10.

Place the Connector/J in:

cp mysql-connector-java-5.1.10-bin.jar $GF_HOME/glassfish/lib/

STEP 2.2: Provide JNDI

In GlassfishV3:

  • Create JDBC Connection Pool: (Admin GUI -> Application Server -> Resources -> JDBC -> Connection Pools)

  • Create JDBC Resources (Admin GUI -> Application Server -> Resources -> JDBC -> JDBC Resources)

Restart Glassfish and Ping the JDBC Connection!

STEP 3: Roller 4

STEP 3.1: Download Roller

Download Roller from here.
For more detailed information about installation refer to the Roller Installation Guide!

STEP 3.2: Create Database
mysql -u root -p

password: *****
create database rollerdb;

grant all on rollerdb.* to scott@'%' identified by 'tiger';

grant all on rollerdb.* to scott@localhost identified by 'tiger';

quit
STEP 3.3: Create roller-custom.properties

To connect to the MySQL database you should create the roller-custom.properties file in either 2 ways “as far as I noticed“:

  • Roller will interact with database Directly:
    installation.type=auto
    database.configurationType=jdbc
    database.jdbc.driverClass=com.mysql.jdbc.Driver
    database.jdbc.connectionURL=jdbc:mysql://localhost:3306/rollerdb
    database.jdbc.username=scott
    database.jdbc.password=tiger
    
    mail.configurationType=properties
    mail.hostName=smtp-server.example.com
    mail.username=scott
    mail.password=tiger

    Place it in:

    mv roller-custom.properties $ROLLER_DIR/WEB-INF/classes/
  • Roller will interact with database through the JNDI:
    installation.type=auto
    database.configurationType=jndi
    database.jndi.name=jdbc/rollerdb
    
    mail.configurationType=jndi
    mail.jndi.name=mail/Session
    mail.configurationType=properties
    mail.hostName=smtp-server.example.com
    mail.username=scott
    mail.password=tiger

    Place it in:

    mv roller-custom.properties $ROLLER_DIR/WEB-INF/classes/

    Make sure that the following Descriptor is placed in this directory:

    ls $ROLLER_DIR/WEB-INF/sun-web.xml
STEP 3.4: Deploy Roller

Deployment must be easy and straightforward too from the Admin GUI, or You can place the $ROLLER_DIR in the autodeploy directory if you want just to try it out.

STEP 4: A Problem To Be Avoid

I only got Roller and GlassFishV3 working together by disabling the following JPA configuration and setting its flag to false and then adding it to “roller-custom.properties“:
openjpa.QueryCompilationCache=false

Enjoy blogging 😉

Design Patterns In Object-Oriented Software

November 3, 2009 6 comments

In Computer Science, a Design Pattern is a way of having a solution of a certain reoccurring problem. This solution is usually the best practice to solve that problem so there is no need to invent a new solution unless it appeared eventually that it is ultimately necessary to have a new best practice solution to that problem.

In other words, Design Patterns are one approach of the Software Reuse concept.

A Design Pattern is usually aimed at software components design in the software engineering. This concept became more popular after the book: Design Patterns: Elements of Reusable Object-Oriented Software. This book was written by 4 authors who are referred to as the Gang of Four or GoF. This book discusses 23 software design patterns that I think every developer must know so they can come up with good software design in a timely-efficient manner for their intended software system. According to the GoF book, these patters were classified by 3 categories: Creational Patterns, Structural Patterns, and Behavioral Patterns.

 

Creational Patterns

Creational Patterns provide the best way in which an object can be instantiated/created that can suit certain situations.

  1. Abstract Factory
  2. Builder
  3. Factory Method
  4. Prototype
  5. Singleton

 

Structural Patterns

Structural Patterns define the best ways to identify relationships between entities.

  1. Adapter
  2. Bridge
  3. Composite
  4. Decorator
  5. Facade
  6. Flyweight
  7. Proxy

 

Behavioral Patterns

Behavioral Patterns define the best ways to communicate between objects.

  1. Chain of Responsibility
  2. Command
  3. Interpreter
  4. Iterator
  5. Mediator
  6. Memento
  7. Observer
  8. State
  9. Strategy
  10. Template Method
  11. Visitor

 

That sums up 23 classic design patterns the I will try to pass through one by one to illustrate them in details and add that to my experience!

Please, read comment# 6

Your comments are highly appreciated!