The tools of the JDT provide a comprehensive range of features for supporting the development of Java applications. In a nutshell, the JDT supports the following:
These features for supporting the construction of Java applications are only a subset of those required for effectively developing J2EE systems. The tools of the Eclipse JDT do not accommodate J2EE components. For this task, the Eclipse workbench requires the installation of plug-in tools that supplement the Java development capabilities of the JDT. Fortunately, a range of Eclipse tools is available for this very purpose.
Two J2EE toolsets that consistently rank toward the top of the active plug-ins lists on various Eclipse Web sites are Lomboz from Object Learn, and MyEclipse from Genuitec. Each product transforms the Eclipse workbench into a J2EE development platform, adding all the wizards, editors, and views necessary for producing J2EE applications.
Lomboz is available as open source. Full details of this tool, including documentation and installation instructions, can be found at http://www.objectlearn.com/products/lomboz.jsp.
MyEclipse is a commercial product, with licenses available on a yearly subscription basis. Surprisingly, for a product aimed at enterprise-level development, MyEclipse does not carry an enterprise-sized price, being relatively low-cost per developer seat. A fully featured version of the software is available for download on a 30-day trial from the MyEclipse Web site. See http://www.myeclipse.com for download details and licensing information.
For our discussion on IDE enterprise development features, the functionality shown uses Eclipse 3.0 with the MyEclipse 3.7 tools installed. The discussion covers the following:
Collectively, these features provide a highly productive J2EE development environment.
Code wizards rely on passive code generation to generate much of the boilerplate code associated with the task of programming. They offer a significant saving in terms of time and effort.
To take advantage of the productivity gains passive code generation affords, it is worthwhile selecting an IDE that provides code wizards for some of the more common J2EE operations.
Passive code generation is described in Chapter 6.
The base JDT provides wizards for generating common Java artifacts such as classes and interfaces. Installing MyEclipse enhances the Eclipse workbench with an additional set of wizards that target J2EE components.
The wizards available include project-level wizards for generating Web applications (WAR), EJB components (JAR), and enterprise application (EAR) deployments. MyEclipse also adds wizards for generating code-level artifacts, including support for generating the following:
Chapter 6 covers XDoclet, and Chapter 7 introduces Hibernate.
Figure 13-2 shows the MyEclipse EJB Wizard, used for generating XDoclet based EJB components.
Figure 13-2. MyEclipse EJB Wizard.
The EJB wizard provided by MyEclipse is template based. From the templates available, enterprise bean types of session, entity, and message-driven beans can be autogenerated. Note that the code generated is XDoclet based, and the code wizard generates a single bean implementation adorned with XDoclet annotations.
Design options for working with EJB technology are discussed in Chapter 4.
Editor Support for Multiple File Types
The editor is the tool around which the workbench revolves. A powerful code editor contributes immensely to developer productivity. In this regard, the Eclipse Java editor is very advanced and offers a number of time saving features. As an example, here are some of the features from the Eclipse editor's source menu that you may find particularly useful.
You should expect most Java development tools to offer similar time saving features.
Learning the keyboard mappings for invoking these features without having to resort to pointing and clicking with the mouse makes coding a faster process.
J2EE applications require editor support for file types other than Java source. A typical J2EE project could comprise the following:
The editor should help us to quickly and accurately write files of all these types and should afford features such as context-sensitive help, syntax highlighting, and code assist (sometimes called code completion).
The Apache Velocity template engine is covered in Chapter 6.
Code assist, or code completion, is the ability of the editor to display context-sensitive information relating to a particular element in the editor. For example, in the Java editor, a code assist feature would prompt the developer with a list of the available methods for an instance variable of a given type. This functionality is given various names by various IDE vendors. This chapter uses the Eclipse term code assist.
The plug-in model of the Eclipse platform makes it ideally suited for dealing with the various file types of J2EE projects. One primary file type not directly supported by Eclipse is JSP. Here, the MyEclipse plug-in adds JSP editor support, providing code assist and syntax highlighting features, and allows the JSP to be syntax-checked and previewed prior to deployment.
A prerequisite for any IDE is its ability to integrate with Apache Ant for performing build tasks. An IDE is an unsuitable tool for constructing a reliable and repeatable build process because most development platforms lack the functionality to cover all of the eventualities required of a build system. For the majority of projects, the Apache Ant build utility is used for this purpose. In order for an IDE to integrate with the build process, it must be able to invoke Ant build file targets directly.
The Apache Ant build utility is described in Chapter 12.
The ability to integrate an Ant build file into the IDE is especially significant if code generation tools such as AndroMDA and XDoclet form an integral part of the build process, as these tools require Ant for invocation.
The MDA tool AndroMDA is covered in Chapter 8.
The Eclipse developers recognize the importance of Ant's role in Java software engineering and ensure that Ant is well supported by the Eclipse workbench. No additional plug-in is required to support Ant integration.
Figure 13-3 illustrates the Ant view, which forms an integral part of the Eclipse workbench.
Figure 13-3. Eclipse Ant build file view.
The Ant view lists all targets in a build file. Build targets can be invoked directly from the workbench using the Ant view. All output generated by Ant is written to the Eclipse workbench's console.
For writing build files, the Eclipse workbench comes with an Ant file-aware editor, which can be associated with all XML file types and provides syntax coloring and code assist for Ant tasks.
This level of integration with Ant makes it possible to write and run build files within the confines of the Eclipse workbench, thereby providing a single environment for project development work.
Working with Code Generators
If a project is using a code generator, then the chosen IDE should both integrate with the code generator and work with the generated code.
A major criterion for integrating the IDE with a code generator is the ability of the IDE to invoke the generator by executing targets in an Ant build file. As we learned in the previous section, Eclipse is very accomplished in this area. Furthermore, the IDE should be able to contend with multiple source paths, because it is good practice to output generated source to a different directory than that of handwritten code. This is possible with Eclipse because Java projects may define multiple source paths.
For working with template-driven code generators, it is desirable for the IDE to provide support for editing the template files. An open source editor for Velocity templates is available for Eclipse. The plug-in Veloedit can be downloaded from http://veloedit.sourceforge.net.
Figure 13-4 shows Veloedit editing an AndroMDA cartridge template. The editor supports both syntax highlighting and code assist for Velocity files.
Figure 13-4. Editing a Velocity template with Veloedit.
Velocity is becoming widely used for code generation, so the Veloedit plug-in enjoys a high number of downloadscurrently, about a thousand downloads a month, which is a significant amount.
The MyEclipse plug-in makes extensive use of XDoclet for generating J2EE components. As we have seen, the EJB wizard generates a bean class annotated with XDoclet attributes.
MyEclipse extends the workbench to ensure XDoclet is well supported and adds code-assist support to the editor for the embedded XDoclet tags. Execution of the XDoclet engine for a MyEclipse project is controlled by a project Ant build file named xdoclet-build.xml. The contents of this build file should not be edited directly. Instead, MyEclipse associates the XDoclet settings with the properties of the EJB project. These properties can be accessed by right-clicking on the project and selecting the Properties menu item. Figure 13-5 displays the various XDoclet properties dialog used for controlling code generation in the project.
Figure 13-5. Setting XDoclet properties with MyEclipse.
The setting for the destDir attribute that specifies the location of generated source defaults to the same location as the Java source directory.
Accepting this configuration would see generated source mixed up with handwritten code. In line with code generation best practice, you should consider changing this setting to a directory dedicated to holding the generated source. Add this new directory as a source path to your Eclipse project.
Having established a suitable configuration, the XDoclet build script is run via a MyEclipse menu item, available by right-clicking on the project in the package explorer view.
Server Control and Application Deployment
To operate as a fully integrated environment, the IDE must have the capability to deploy J2EE applications. It should also offer the functionality to control the target J2EE server, allowing the developer to start and stop the server without the need to leave the IDE.
These integration features require the IDE to keep pace with new versions of the different application servers. You must also check that your chosen IDE or Eclipse plug-in supports your particular application server.
Eclipse relies on plug-in tools for incorporating this functionality into the workbench. For deployment, MyEclipse adds a deployment wizard to the workbench that enables J2EE modules to be deployed to a number of J2EE server types. Figure 13-6 shows the MyEclipse deployment dialog with a J2EE EAR project selected. The packaged application targets instances of the JBoss and WebLogic servers. For each server selected, you may specifying the deployment type. From the example deployment setup in Figure 13-6, an exploded deployment is specified for WLS, while for JBoss the application is deployed as an EAR file. The type of deployment selected depends on what the application server supports.
Figure 13-6. MyEclipse J2EE project deployment dialog.
MyEclipse allows J2EE servers to be configured within the IDE and adds toolbar items to enable each configured server to be started or stopped from within the Eclipse workbench. This level of integration between application server and IDE provides for the rapid transition of newly written code into a running state, where it can be tested and debugged.
Eclipse's use of plug-in tools enables the integration of UML modeling tools into the workbench. A number of modeling tools are available as Eclipse plug-ins. Omondo offers Eclipse-UML, available from http://www.omondo.com. In addition, Borland produces an Eclipse modeling tool as part of its Together family of products; see http://www.borland.com.
Chapter 5 provides an overview of the main UML diagrams and discusses modeling tools.
Modeling tools generally add their own perspective to the Eclipse workbench. Switching between the modeling and Java perspectives offers a convenient means of moving from model to code, and vice versa. This approach ensures the model is closely associated with the code, thereby helping to prevent the model from being neglected as development progresses.
Few J2EE solutions are constructed without an underlying data repository; most enterprise systems use a relational database.
One area where many IDEs are still trailing the best-of-breed tools is in database support. Few. if any, IDEs offer the same level of functionality as specialized database tools such as DBArtisan, ERwin, or TOAD. These tools support such features as writing stored procedures and database triggers, generating database performance statistics, and in some cases modeling entity relationships for schema designs. Some IDE products offer limited support in this area. For example, Together ControlCenter can generate ER diagrams reverse-engineered from the database and can generate DDL scripts from an ER diagram.
Although they do not offer the same level of sophistication as the best-of-breed database tools, most IDEs offer some form of database access. A few open source database tools are available for Eclipse. One offering is Quantum DB, a useful query editor that allows the execution of SQL statements and the contents of database tables to be interrogated via a JDBC driver. MyEclipse also includes a tool with similar functionality. Although limited, this simple functionality comes in very useful and can be a great time saver when it comes to checking the results of test runs or preparing test data on the database.
Over time, mainstream database-management products may migrate to the Eclipse platform, making a fully integrated development environment possible.