JBuilder for Cocoon developing

by Michal Durdina

About JBuilder

Although everybody certainly knows what JBuilder is, I would like to compose few facts here. From my perspective, though. I am a big fan of Borland products for developers, maybe because I used to be Pascal and later Dephi developer. Borland had no rivals on the field of IDEs for these programming languages. They had the power, ease of use and great documentation, so we loved them. JBuilder is another such IDE for Java developing and it is not a newcomer. Today's version of JBuilder is version 6 and it is really good (except the cost).

Note:
Oracle bought JBuilder 3 sources for their JDeveloper and uses them today in Oracle app server :)

Features

JBuilder is made by Borland Inc., the company with long history in IDE development. What I really like on Borland products is that they really help. Various tools they contain are easily accessible, intuitive to use and pretty much configurable. Development with such set of tools is fast so Borland likes to put a label RAD (Rapid Application Development) to its IDEs.

Organized developing

While developing in any of Borland IDEs, you always have a documentation at your hand. This is very important and especially for new-byes, the context-help can be very helpful. JBuilder is not an exception. Using JBuilder for developing J2SE or J2EE is a pleasure. When developing J2EE application (what Cocoon is), all files of your web app are browsable in tree view and every file is editable by editors applicable only to its specific type. You can control all dependencies by specifying paths for jars, classes, documents (such a html, xml), configuration files (sitemap), or resources (gifs).

Running, testing, debugging...

Running and debugging your web application is seamless because for running all web applications JBuilder uses Tomcat integrated in IDE. If you need to test your web application on different web server, JBuilder creates Java archives (jars) and web archive (war) from your web application and all you need to do is set the path where the resulting war file should be saved. Also, all the Java classes could be debugged directly from the IDE, even XSP pages compiled by Cocoon located in /work directory. I think there is nothing else to be said.

JBuilder means power

Although JBuilder is famous for developing web applications based on JSP, Cocoon developing in JBuilder is almost as easy. There is much more than web developing that JBuilder offers. Unfortunately, such a powerful IDE is not for free. Your option, however, is to use the evaluation version of JBuilder Professional or JBuilder Enterprise. For 60 days, though.

Note:
For full list of features you need to follow link to Borland

Snap shot

Next picture can give you better idea what JBuilder consist of and how it works. Do not get frustrated by its look. It does not contain fancy M$ toolbars, menus or icons. It is written in Java so it uses Swing for its user interface, which has kind of limited capabilities. On the other hand, you can be pretty sure it will look and run similar on Linux or Solaris.

(click on image for larger version)

JBuilder5 snap shot

Configuring JBuilder for Cocoon2

In following paragraphs I present experiences with configuration of JBuilder for running Cocoon2 applications. I achieved this knowledge after several hours of simple proof testing. I've been using JBuilder 5, Tomcat 4.01 and Cocoon 2.0rc2. Have also these or newer products installed on your hard disk to achieve expected result. Please remember that although I tested presented settings and configurations, I cannot be held responsible for any damages on your data. So please, backup your data before experimenting on your application.

Note:
If you would like to jump to the fire right now, use provided example here. However, there are few settings to JBuilder IDE anyway, so read html readme included in example project.

Creating new project

After opening JBuilder, it is necessary to create new project for your Cocoon2 web application.

  • In File | New Project... change only project name and project root path in step 1
  • Remove all required libraries in step 2
  • In File | New... choose web application from Web tab
  • Choose name for your web app (will be used as context name in web server)
  • Create directory for your web app under project root directory (you can use project root directory, but to organize your project better, create new directory with name same as one chosen for your web app)
  • Copy all your web files (xml, xsp, xsl, ...) to web app directory creating auxiliary directory tree (i.e. documents, stylesheets, images, entities...)
  • Copy deployment descriptor web.xml to WEB-INF directory of your web application (replace empty one)
  • Copy sitemap.xmap, cocoon.xconf, (logkit.xconf) to web app directory (sitemap.xmap entries should respect created directory structure, but you can change it later if needed)

Setting up project properties

There are some additional settings needed for Cocoon2 web application type.

  • In order of classpaths to be set properly for Cocoon2 libraries, go to Project | Project Properties... and on Paths tab choose Required libraries | Add... . Define new library named Cocoon2Lib (or similar) and add all libraries (jars) from your Cocoon2 distribution. Do not forget to include cocoon.jar from build directory.
  • In web app properties (right click in project pane) on WebApp tab add additional files that should be included to your project. Xml, xsd, dtd, xsp and xsl is minimal option in my opinion, but final decision depends on requirement of your application. These will be automatically included to your project and will be copied to web archive (war) file after build.
  • To include configuration files sitamp.xmap and cocoon.xconf to project, there are some additional settings needed, because their file extensions are not recognized by default. In Tools | IDE Options... on File types tab find XML file among Recognized file types and add xmap and xconf extensions. After this change, JBuilder will recognize these new file types and will treat them as any other xml file, thus it will display them right in editor and automatically include them to your project (if you have set this option for xml files).
  • Unfortunately, to take these settings effective, you need to restart JBuilder. Do not forget to save your project before performing this action!

Preparing for launch

Cocoon2 web application requires Tomcat 4.0 in order to run in JBuilder and JBuilder 5 normally uses Tomcat version 3.2 which is good only for Cocoon version 1.x. Fortunately, JBuilder can run Tomcat 4.0 after few settings.

Note:
JBuilder 5 Enterprise contains Cocoon version 1.8 is distribution
  • In Project | Project Properties... choose servers tab and choose Tomcat 4 server for setup. All you need to do is to point JBuilder to Tomcat 4 distribution root directory on your hard disk. It is not much configurable, but working approach. Of course, leave Tomcat 4 option selected for your project.
  • Cocoon2 component "entity resolver" (defined in cocoon.xconf) needs external file CatalogManager.properties located in WEB-INF/classes directory of your web app. The easiest way how to include it automatically is to copy the file to src directory in your project (if does not exist - create one) and treat it as a resource. Then in web app properties (right click | Properties...) on Classes tab add this file to Required classes, packages and resources.
  • Now everything should be set in order to run your web application (unless you need to make some changes in sitemap or Cocoon configuration). After building and (or just) running the project, JBuilder starts Tomcat and creates context for you web application. You can use any Internet browser to test the application. However, to use browser integrated in JBuilder, you need to specify what page should be initially displayed. To accomplish this, go to Project | Project properties... and set the Launch URI in Run | JSP/Servlet tab.
  • You all set! Welcome to the professional Cocoon2 developing!

Tips for Cocoon developing using JBuilder

This section contains tips for running and developing Cocoon2 applications under JBuilder. I did not want to put them to general Tips & Hints section, though they are kind of hidden now.

  • If you also develop Java classes under your project (i.e. actions, customized Cocoon2 components or just any classes used in your xsp pages), they are automatically included to WEB-INF/classes directory in case they are located in src directory. If you would like to organize them as jar archive, and include generated jar file to WEB-INF/lib directory, use following technique. In Wizards | Archive Builder... create archive (jar) of your classes (all your classes in src directory by default) and save the file for example in your project root directory. Then add this archive to your projects required libraries. To include any jars to WEB-INF/lib directory, you need to select include option for required library in your web application dependencies. You can also include Cocoon2 jars if you are about to build your web application for deployment.
  • If you want to test your Java classes included in your web project, you do not have to always run web server for this purpose. To run Java interpreter instead of web server create new configuration in Run | Configuration... and on Run | Application tab set Main class to any class containing static method main(). Run this configuration from toolbar Run button and choose recently created configuration from pop-down menu.
  • When deploying web application turn off debugging options either by setting your default project properties or better by creating new configuration for this purpose.