Friday, May 01, 2009

Mercurial on GlassFish 2.1 Using Multiple Repositories

Introduction

In this tutorial I explain the basics of creating multiple Mercurial repositories, and then configuring GlassFish 2.1 to connect and display them. Mercurial is an open source source control system. GlassFish is an open source Java™ application server. I will not explain how to install Mercurial, nor GlassFish. The respective sites have excellent documentation on how to install them.

Creating Repositories

1. Create a directory called /repos.

2. Using the command prompt, navigate to the /repos directory and issue the following commands.
hg init alpha
hg init beta
hg init omega
This will create three new Mercurial repositories.

3. Change to the respective repositories and add a file called hgrc to the .hg directory. This file should contain a contact and a description of the repository. Here is a representative example from my alpha repository.

[web]
contact = John Yeary <jyearyATbluelotussoftwareDOTcom>
description = Alpha source code repository.
This information will be displayed on our main page.

NetBeans 6.5

1. Using NetBeans create a new Project -> Java Web ->Web Application.

2. Call the project Mercurial.



3. The default Context Path is the project name. We will change it from /Mercurial to /mercurial.



4. Click Finish. This will create a basic web project which will compile to a nice WAR file for deployment on GlassFish.

5. We will begin to modify our project by removing the index.jsp file.

6. Next go to the Web Pages -> WEB-INF directory. In here you will find the default web.xml file. Open it in the editor.

7. Follow the directions from Jean-Francois Arcand's Blog on Enabling CGI support in GlassFish. An example of my web.xml file is displayed below. This will enable the CGI servlet which is used by Mercurial to display the repositories.
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>cgi</servlet-name>
<servlet-class>org.apache.catalina.servlets.CGIServlet</servlet-class>
<init-param>
<param-name>debug</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>cgiPathPrefix</param-name>
<param-value>WEB-INF/cgi</param-value>
</init-param>
<load-on-startup>5</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>cgi</servlet-name>
<url-pattern>/cgi-bin/*</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

8. Next we will create a sub-directory WEB-INF called cgi. This will contain our CGI applications.

9. Obtain a copy of the source code for your version of Mercurial. Locate the hgwebdir.cgi file and copy it to your WEB-INF/cgi directory.

10. Create a file called hgweb.config in the WEB-INF/cgi directory. The hgwebdir.cgi application expects this file to exist and point to your repositories. The hgwebdir.cgi file contains help on configuring the file. Here is an example configuration based on our setup.

[paths]
/ = /repos/*

This will allow the hgwebdir.cgi to map all repositories located in the /repos directory.

11. Next we modify the web.xml file and change the welcome files list to point to the application.
<welcome-file-list>
  <welcome-file>cgi-bin/hgwebdir.cgi</welcome-file>
</welcome-file-list>
12. Click on Run and you should be delighted to see the following.


Issues

If you encounter any errors, or nothing appears, you can enable debugging for python by un-commenting the following lines in the hgwebdir.cgi file.
# Uncomment to send python tracebacks to the browser if an error occurs:
#import cgitb
#cgitb.enable()
You may also enable debugging on the cgi application by changing the debug parameter to 1 in the web.xml file
<init-param>
<param-name>debug</param-name>
<param-value>1</param-value>
</init-param>

Here is a copy of my NetBeans Mercurial Project. It is itself a Mercurial repository.

Wednesday, April 01, 2009

JSF 1.2: Visual JSF ( Project Woodstock) Table Row Striping, or Alternating Row Colors

I recently encountered some issues with setting the class attribute of my table rows using Javascript on Internet Explorer, and Firefox 3.0.8. The class was designed to change the background of the <td> elements of my table. I finally decided that I would try using the TableRowGroup styleClasses tag to try to accomplish the "striping", or alternating the color of odd and even rows in the table. The tag description indicates that it is as easy as adding two style classes which will accomplish this. This is not quite true if you have tried it.

The CSS for the table component in Woodstock has defined a background-color of white (#FFFFFF). This makes overriding it quite difficult.
I accomplished overriding it by placing the same element in the stylesheet.css file located in the project.

Here is what I added:
I then added my new css classes to the TableRowGroup as seen below.



The final result was to produce an elegent table with alternating colored rows.



Here is a link to the NetBeans 6.5 project on BitBucket: TableAlternateRowStriping

Wednesday, February 18, 2009

Drupal on GlassFish using Quercus

I will explain how to get Drupal running on GlassFish in 10 minutes.

Requirements:
Database:
  1. Create the Drupal user in the database.
    GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY 'drupal';
    Note: This is not secure and should only be used for demo.

  2. Create a new database in mySQL called drupal.
    create database drupal character set utf8;
Quercus:

Download and extract the quercus-3.2.1.war file.
jar -xvf quercus-3.2.1.war WEB-INF
Drupal:
  1. Download and extract Drupal 6.9
  2. Copy the WEB-INF directory and files from the Quercus into the Drupal directory.
NetBeans:

  1. Create a new project in NetBeans. Choose Java Web and Web Application with Existing Sources.


  2. Fill in the Name and location properties for the project.

    Note: Please make sure that you choose a different folder for the project files. Please see the image below as an example.


  3. Next select the application server, and set the Context Path. I renamed my context to /drupal


  4. Next select the Web Pages folder. This should be the top directory of the Drupal directory you extracted. This is the directory which contains index.php.


  5. Click Finish

  6. Open the project and navigate to the Web Pages folder. Navigate to the sites --> default directory. Right click on the default.settings.php file and copy. Paste the file back into the directory. Right click on the file it should be named something like default.settings_1.php, rename the file to settings.

    Note: NetBeans will append the .php to the end of the file.


  7. Right click on the project and select Properties. This will bring up the project properties. Select the Libraries Category. Here you will see the files that were included from Quercus 3.1.2 which were in the WEB-INF/lib directory.

  8. Click on Add Library and select MySQL JDBC Driver. Click OK.


  9. Finally Run Main Project (F6).


Drupal Configuration:

If you were successful, you should see the Drupal Configuration page.



  1. Select Install Drupal in English (You may choose differently based on your requirements).


  2. Fill in the database with the information we created earlier.

    • Check mysqli
    • Database Name: drupal
    • Database Username : drupal
    • Database Password: drupal


    Click Save and Continue.


  3. That will complete the database installation and bring up the Site Configuration Screen. Fill in the values and click Save and Continue.


  4. Finished. You should get an Installation Complete screen. Click on your new site.

    Note: My installation has an error message because I don't have SMTP configured on my Mac.



Congratulations! You have Drupal 6.9 running on Quercus 3.1.2 on GlassFish 2.1.

Popular Posts