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.

Friday, February 06, 2009

Book Review: Pro Netbeans IDE 6 Rich Client Platform Edition

Disclaimer: Adam Myatt and I have been on the JavaOne 2008 and 2009 Tools and Languages Review Committee. I don't believe that there is any predjudice for/against the book, but in the interest of disclosure I thought it important to mention. Don't you wish politicians had that much honesty?

I had the pleasure of reading the Pro NetBeans IDE 6 Rich Client Platform Edition book by Adam Myatt. I had read it a while ago, but I did not have the time to do a review on it. The book is sixteen chapters long, and covers a variety of topics from download and installation to developing rich client applications. The book covers version 6/6.1 of NetBeans, but there is significant applicability to version 6.5 to make it worth purchasing.

The book has a primary target of new users to the NetBeans IDE. It is designed to take you from novice user to power user in a systematic organized way. The book is sufficiently modular that you can choose to read individual modules, or go from cover to cover. The chapters stand on their own so that you do not need to worry about missing something in a previous chapter if you decide to browse.

Based on the easy reading style and effectiveness of communicating complex topics, I would give the book (4/5) stars.

Chapter 1:
Downloading, Installing, and Customizing NetBeans

This chapter covers the basics of installation, and explains a number of options available for configuration.

Chapter 2:
The Source Editor

Here we cover the basics of the source code editor and its windows. It also covers some interesting features of the source editor like the error stripe and annotation glyphs. The error stripe allows the user to go directly to any errors which are in the code. The annotation glyph provides the user with suggestions. These may be as simple as reminding you to mark @Override on an overridden method.

One of the best discussions in the chapter has to do with built-in and custom macros you can create to simplify coding tasks. This was a great explanation of how it works.

Chapter 3:
Code Completion and Templates

Code completion is what makes an IDE so valuable. This chapter covers the NetBeans code completion technology in detail.

It also covers code templates which are a boon to any developer who learns to use them. Adam really explains this in a manner that makes them easy to learn and use.

Chapter 4:
Debugging

I thought I was fairly sophisticated in my use of debugging. This chapter made me feel inadequate. After reading it and implementing some of the ideas, I feel I am back to being an expert.

Note: I found one error on page 95. The third paragraph has Run --> Run File -->Run Debug Evaluate Expression. It should be Run --> Run File --> Run to Cursor.

I would buy the book for this chapter alone.


Chapter 5:
Profiling

This chapter covers profiling for performance. Sun and NetBeans has spent a lot of time creating this technology (like DTrace), instrumenting, and providing tools. It is a shame that they really have not promoted these capabilities to the developer community.

Adam has spent a lot of time detailing profiling and providing great examples to get you into it. His explanations may be enough to encourage developers to use these really great tools.

This chapter also includes how to profile remote JVMs and application servers. It is a really slick explanation and demo.

Chapter 6:
Managing Version Control

This chapter covers version control system implementations in NetBeans. It covers CVS and Subversion. Since the book was written, the Subversion implementaion has had numerous improvements. NetBeans 6.1 and 6.5 also include support for Mercurial.

Chapter 7:
Generating and Accessing Javadoc

This chapter covers Javadocs and tools in the IDE to make Javadocs easier to create. I must admit I thought they were already easy, but there are some features to make it even easier including code completion.

Chapter 8:
Managing Builds with Ant and Maven

This covers Apache Ant and Maven implementations in NetBeans. Adam covers some of the features of Ant with a high degree of skill. He covers the NetBeans implementation very well.

The section on Maven is a weak spot in the book. In fairness, the version of NetBeans which the book was based on had poor Maven capabilites. Version 6.5 of NetBeans has much better tools for handling Maven.

Chapter 9:
JUnit Testing

This chapter covers JUnit testing. This is another chapter that is a little to weak. NetBeans 6.0, 6.1, and 6.5 have some really great implementations for doing JUnit testing. This chapter does not do it justice.

Chapter 10:
Refactoring

This chapter covers refactoring. NetBeans has some really great refactoring tools.

JetBrains IntelliJ IDEA is the gold standard for refactoring, but each generation of NetBeans brings it one step closer.

There are some comprehensive explanations of how to use the refactoring tools in NetBeans. If you want to master the IDE, this chapter, and chapters 4, and 11 are a must.

Chapter 11:
Code Quality Tools

This chapter covers some of the really great plugins that are available for NetBeans including: Checkstyle, PMD, and SQE (FindBugs). If you are not using these static analysis tools in your code, you are doing yourself and customers a disservice. This chapter covers the tools in enough detail to get your interest. These plugins are in constant development, and you should check the latest versions and updates out.

These tools will make your code much better. You as a developer need to understand why. When Checkstyle marks code as a "Magic Number", you need to read the explanation. Understanding the why will help you to avoid these problems in your future code.

Chapter 12:
Developing JRuby/Ruby on Rails Applications

This chapter covers developing JRuby, and Ruby-on-Rails (RoR) applications using NetBeans. The chapter is not designed to teach you to program in Ruby, but to show you what features are available in the IDE. The NetBeans support for Ruby is fantastic. A number of other IDE developers are trying to emulate the functionality. I think that most Ruby developers will find that the support is a quantum leap in terms of ease and functionality over more traditional tools.

There is a note on page 297 which explains a really neat feature. If an existing application is deployed using Webrick, or Mongrel on port 3000, the IDE will increment the port number to prevent port in use errors.

Chapter 13:
Developing Web Applications

This is a long chapter covering web application development. The first part of the chapter covers the functionality of the IDE in terms of what features it provides. This includes items like the Javascript and CSS editors. Both of these tools are really useful.

The Javascript editor and debugger have been vastly improved in NetBeans 6.5.

The CSS editor with a change viewer make designing, or changing a CSS file a snap.

The chapter also covers the application server features and HTTP monitor. Specifically it covers Apache Tomcat and GlassFish. It explains how to add additional servers like JBoss, or Websphere to allow those server deployments.

The second half of the chapter covers web application development frameworks. The section covers Struts, Struts 2, Visual Java Server Faces (JSF) (Project Woodstock), and JMaki.

The Struts and Struts 2 section is relatively small. It provides the user with the basics of how to create and use Struts based projects.

The section on Visual JSF development is extensive and makes the book worth purchasing. The explanation on how to get started will set you on the right path. The section on visual data binding is elegant and simple. It also covers the Visual Database Query Editor. This functionality has been updated in NetBeans 6.5, but the explanation here still applies.

Note: Visual JavaServerFaces (JSF) development in NetBeans has been frozen. The promise of Project Woodstock in a version 4.3 release and beyond has been abandoned officially by Sun. The current supported version is 4.2. It will continued to be supported by the NetBeans team for the foreseeable future. The push by Sun is to provide support using third party providers of JSF components. The best of these providers is ICEFaces. They have a really great set of components, and have provided a transition plan for Project Woodstock developers.

The section on JMaki is too brief to really provide a great explanation of this great technology.

Chapter 14:
Developing Web Services: JAX-WS, SOA, BPEL, and RESTful

This chapter covers JAX-WS, SOA, BPEL, and RESTful services. These projects have undergone extensive updates which makes the information here slightly dated. The basic procedures are the same, but there are better tools in NetBeans 6.5.

Chapter 15:
Developing GUI Applications

This chapter covers GUI application development. It is the best aggregation on the subject I have seen. There are a number of tutorials on the NetBeans site, and some good explanations of the features, but this is the best explanation I have seen. There is a great tutorial example of how to use the various components of the IDE to do visual Swing development. I was impressed and learned some new things too.

There is a section on the Swing Application Framework (JSR-296) which is the best I have seen. This technology is supposed to make Swing development easier. I used the information in here to create an enterprise wide application in 1/4 of the time it normally takes. It was also less error prone since the framework handles threading and concurrency issues.

Note: On page 427 there is a code example that has the user add a showHelloWorld method. There is a missing variable that needs to be added. It should have:
private JDialog helloWorldBox;
There is another section on Beans Binding (JSR-296) which covers another ease of use technology for Swing. It allows the developer to bind data components to Swing components in an easy and consistent way. The explanation here of the technology combined with JSR-295 makes Swing development easy. It also covers the Database Table Editor to make modifying tables easy to use as part of the binding process.
Note: Page 431, last paragraph indicates that you can use the DOUGHNUTS table node to use the table editor, this is not correct. You must open the table, and select a column to open the table editor.

Note: Page 442, to use the validator you have created, you must compile the code first. Either by selecting the class itself and compiling it, or clean and building your project.

I personally found that the GUI project development section was crucial to me for using these great new technologies, and development of a successful enterprise Swing application.

Chapter 16:

Developing Rich Client Applications

This chapter covers the development of Rich Client Platform applications using the NetBeans platform as the base for your application. This section provides an introduction to the technology, and the basics of how to create your own branded rich client applications.

Summary:

I would recommend this book to anyone who wants to learn more about the NetBeans IDE.

Based on the easy reading style and effectiveness of communicating complex topics, I would give the book (4/5) stars.

Sunday, February 01, 2009

Quercus PHP 3.2.1 on GlassFish 2.1

I am trying to consolidate a number of applications running on various platforms to GlassFish, if possible. So far I have been incredibly successful with Ruby using JRuby. Our project tracking software (bugs/news/wiki/forums/repository browser) are running on Redmine using JRuby.

Based on the success of using Ruby (RoR), I decided to trying moving some PHP applications over to GlassFish.

I read a great blog article by Ludovic Champenois called 100% Java Quercus PHP engine running in GlassFish Java EE 5 Application Server It describes how to use an open source engine called Quercus from Caucho. I tried to follow the directions, but could not get it to work. I imagine because the versions of GlassFish application server and Quercus may have been different. I was not deterred.

I came across a follow-up article by Arun Gupta called PHP in GlassFish using Caucho Quercus. This article was the missing link. The major difference being the placement of the jar files in the domain/domainXX/lib directory.

Here are the application versions I used to get a functional Caucho Quercus PHP implementation running on GlassFish v 2.1

Mac OS X 10.5.6 (Intel x86)

  • GlassFish v 2.1 Build 60e ( 2.1 FCS)
  • Quercus 3.2.1
  • Java(TM) SE Runtime Environment (build 1.6.0_07-b06-146) Java HotSpot(TM) 64-Bit Server VM (build 1.6.0_07-b06-56, mixed mode)

Mac OS X 10.5.6 (PowerPC)

  • GlassFish v 2.1 Build 60e ( 2.1 FCS)
  • Quercus 3.2.1
  • jsr223-api.jar (Project Phobos) Required for Java SE 5.
  • Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_16-b06-284) Java HotSpot(TM) Client VM (build 1.5.0_16-133, mixed mode, sharing)
When I created my projects I used the following web.xml It is based on the example web.xml in the Quercus 3.2.1 war file.

<?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">
<session-config>
   <session-timeout>
       30
   </session-timeout>
</session-config>

<description>Caucho Technology's PHP Implementation</description>
<servlet>
   <servlet-name>Quercus Servlet</servlet-name>
   <servlet-class>com.caucho.quercus.servlet.QuercusServlet</servlet-class>
<!-- Specifies the encoding Quercus should use to read in PHP scripts.
    -->
<!--
    <init-param>
      <param-name>script-encoding</param-name>
      <param-value>UTF-8</param-value>
    </init-param>
    -->

<!-- Tells Quercus to use the following JDBC database and to ignore the
         arguments of mysql_connect().
    -->
<!--
    <init-param>
      <param-name>database</param-name>
      <param-value>jdbc/test</param-value>
    </init-param>
    -->

<!--
    <init-param>
      <param-name>ini-file</param-name>
      <param-value>WEB-INF/php.ini</param-value>
    </init-param>
    -->
</servlet>

<servlet-mapping>
   <servlet-name>Quercus Servlet</servlet-name>
   <url-pattern>*.php</url-pattern>
</servlet-mapping>
<welcome-file-list>
   <welcome-file>index.php</welcome-file>
</welcome-file-list>
</web-app>


This arrangement will allow you run a large number of applications including XWiki, and Drupal. Unfortunately for me, it can not run phpLDAPadmin which I needed.

Popular Posts