Galileo Troubles

Eclipse GalileoAnother year has passed in the Eclipse universe, and this means another minor release number and another Jupiter moon. Eclipse has moved from 3.4 to 3.5 or respectively from Ganymede to Galileo. Using a small gap in my busy development schedule, I decided to install the latest version this morning. Thanks to broadband Internet, the 180 MB JEE package was downloaded in a breeze and installed in a few minutes. Unfortunately, that’s where things stopped being easy.

When I downloaded the PDT plugin for PHP development, I found a bug in it that prevented Eclipse from creating a PHP project from existing sources. After some research on the Internet, I found that this was a well-documented bug which had been fixed in the meantime. I tried installing the latest PDT release via the Eclipse install & update feature, but the process came to a crashing halt with a message that demanded some mylyn jars that could not be found. Although I had no idea why PDT required that particular jar, I dutifully installed the mylyn plugins with the required version number.

Unfortunately, this did not impress Galileo, as it now demanded other jars when installing the PDT update. – Perhaps a case of workspace pollution, I thought. – Clearly, it was time for a fresh start. I scrapped the installation and started anew with a blank workspace and a new install location. This time, everything seemed to install fine. I was able to create Java and PHP projects. However, Galileo suddenly wouldn’t open *.xml, *.xsl, or *.html files any more. It complained that there was no editor for this content type, which appeared fishy since both web tools (WTP) and PDT were installed. I tried to solve the problem by playing around with the configuration, but to no avail.

After several fresh attempts and considerable time spent with looking up error messages on the Internet, I decided to stay with Ganymede. Since I had wasted my entire morning and since I had some real work to do as well, this seemed to be the best course of action. Maybe I will give Galileo another go when an updated distro package becomes available. With Ganymede I never ran into this sort of trouble, despite having PDT, WTP, the Scala plugin and Jboss tools installed. I am still clueless as to what went wrong and I wonder if anybody else had a similar experience.

Make WAR with Eclipse

No, it has nothing to do with armed conflict. Making WAR files is the Java way of packaging, distributing, and deploying web applications. While JAR stands for “Java archive”, WAR stands for “Web application archive”, or simply “Web archive”. In fact, the JAR and WAR formats are both gzipped directories that include a manifest. While a JAR file typically contains a collection of class files, a WAR file contains the entire content that goes into a Java Web application. More precisely, a WAR file contains all the static content, directories, JSPs, beans and classes, libraries, as well as the web.xml deployment descriptor. If you unpack a WAR file, you get a directory structure that mirrors the document root of a deployed application in a web container, such as Tomcat. I recently had to create a Web application in Eclipse. I realised that despite having worked with Eclipse for five years, this is something I never did before, because in the past I used Netbeans for creating web applications. But it’s just as easy in Eclipse. Here are is how:

To create a Java web project, you need to have the following software installed: a Java JDK, a recent version of Eclipse that contains the WTP Web Tools Platform module for Eclipse, and a web container or an application server, such as Tomcat, JBoss, WebSphere, etc.

1…Select File/New/Project from the menu. The following dialogue appears:

webapp-img01.png

2…Select Dynamic Web Project from the list and click on the Next button.
webapp-img02.png

3…Type a name for the new project and select a file system location for it. In the Target Runtime option, specify the web container or application server you using. This server is used to build and deploy your web application. If the drop-down box does not contain the desired server, click New… and select one of the predefined configurations (see Step 4). If you have already defined a Target Runtime, you can skip ahead to Step 6. The Dynamic Web Module version option specifies the architecture you are going to use in the web project. Select the latest version for a new project. Unfortunately, this cannot be changed later. By clicking the Modify… button in the Configuration section, you can select “facets” for your web application. What Eclipse calls “facets” are various building blocks and APIs, such as Java Server Faces, Java Persistence API, etc., that add functionality to your application.

webapp-img03.png

4…The New… button in the Target Runtime section opens a dialogue that lets you select the server on which the application is developed and deployed, which is probably the most important aspect of your configuration. Eclipse offers a number of common configurations for popular servers. If you cannot find your server in this list, click on the Download additional server adapters link and chances are that your server is listed. Make sure that the Create a new local server option is checked, so that you can find the server in the Eclipse server view later on.

webapp-img04.png

5…Once you specified the server type, you need to provide some details about it, such as the installation directory of the server, or the server root, and the JRE you want the server to run on. Click Finish when done.

webapp-img05.png

6…Finally, the dynamic web project wizard prompts you for some basic configuration data. The Context Root is the name that the web container matches with the  location where the application is deployed and simultaneously constitutes the root URL for the web application. The Content Directory specifies the name of the directory that contains the web application files. The Java Source Directory specifies the name of the directory that contains Java source code files. These settings are only relevant to the development machine. Make sure that the Generate deployment descriptor option is checked in order to automatically create the web.xml file. In most cases, you can probably accept the default settings and click Finish.

webapp-img06.png

7…Voilá. You have created a web application, or rather the framework for its development in Eclipse. The new project should now be visible in the Navigator view. There aren’t any files yet, except the ones which were generated automatically by Eclipse. The next step would be to write your web application, and possibly incorporating the application framework of your choice. Piece of cake.

webapp-img07.png

8…The Server view should display the server you have chosen for your project. If everything went OK, you can start and stop the server from this view. The server can be started in normal mode, debug mode, or profiling mode. Debug mode needs to be selected if you want to define breakpoints in your Java code. While you edit sources, such as JSP files, servlets, bean classes, static content, etc., Eclipse automatically redeploys these resources to the running server as soon as you save them. You can view your web application in a separate browser window and receive debug output in Eclipse’s Console view.

webapp-img08.png

9…After you have written your formidable web application, it’s time to share it with the world, or in more technical terms, to distribute and deploy it. The process of creating a distributable WAR file is extremely simple. Select File/Export from the Eclipse menu and click on the WAR file option in the Web category.

webapp-img09.png

10…After clicking the Next button, specify the web project to be packaged, the file destination, and the target server. Although the latter is not a mandatory option, it is probably an important one. The selected server is likely to be the same as the one chosen in Step 3. Click Finish and there you have your masterpiece in a handy WAR format.

Zend Studio for Eclipse

Usually I don’t talk about new product announcements in this blog, because there are just too many of them and often they are only of interest to a small group. Yet, I think the recent release of Zend Studio for Eclipse (Beta) will be exciting news for almost every PHP developer. Last year I had evaluated the previous version of Zend Studio, which is certainly excellent. However, I’ve grown attached to the Eclipse IDE, and therefore I did not make the switch and kept using the PHP Eclipse plugin instead. It seems that Eclipse has gained popularity across the board in the PHP world. Zend has recognised the signs of the time and released an Eclipse version of its flagship product earlier this month. This puts Zend Studio into direct competition with PDT and PHP Eclipse.

The Zend IDE has all the usual niceties, such as code assist, syntax colouring, code fold, class hierarchy view, property inspectors, auto format, and powerful search/replace functions without which most PHP developers probably cannot live any more, but there is even more. In addition to PHP code editing, the IDE also provides JavaScript and CSS editors. I have always wished for the sort of code refactoring functionality for PHP that you get with the Eclipse Java editor. The new Zend Studio finally offers this, although perhaps somewhat less extensively than what Java programmers are used to. At least there’s support for renaming and moving, as well as automatic includes. This alone should be a huge time saver, especially for larger projects with dozens or even hundreds of source files.

Further high-end features include support for PHPUnit Testing, PHPDoc generation, as well as debugging and profiling. I cannot stress enough how important these features are, especially when working in a team. The PHPUnit support generates skeleton test classes for all code elements and thus finally takes the pain out of creating meaningful test suites. Well, the programmer is still responsible for making them meaningful, but there isn’t so much typing involved any more. Likewise, with full PhpDoc support there is finally no more excuse for not including the programmer documentation in the sources. Project managers will probably welcome this, just as the felicitous integration of CVS and Subversion which works right out of the project view. Given “var_dump” and logging I have rarely felt the need for a debugger, but since debugging has always been a strength of Zend Studio, one might welcome this as an additional luxury. The profiler, on the other hand, can prove to be vital when checking large chunks of unfamiliar code for weaknesses.

Other noteworthy features are support for code templates and snippets (probably great for lazy typers with a good memory), inclusion of the open-source PHP/Java bridge which allows using Java classes from PHP and vice versa, and a number of wizards that help to get projects and classes getting off the ground faster, including support for WSDL/SOAP. Perhaps even more noteworthy are the integrated SQL GUI editor and HTML WYSIWYG editor. The SQL GUI offers the typical DB server explorer tree, table data viewing and editing in grids, a query editor with syntax highlighting and BLOB views. This is certainly helpful for casual database development, although “serious” DB developers might still prefer the respective DB manufacturer’s tools in combination with an ORM library. The HTML WYSIWYG editor is another really big addition. It looks a bit like an early version of Dreamweaver and it offers code, design and split-window code/design views. I doubt that it can replace a high-end designer tool, but it is certainly more than sufficient for the typical web application, and perhaps it even allows less artistically inclined programmers to add some visual polish to their pages.

In summary, Zend Studio for Eclipse is a high-end development tool with many advanced productivity features. The product is offered at a price of $254 USD and the final release is announced for the end of 2007. Further information, including a number of demo videos, is available at the Zend website.

Eclipsed by Europa

Eclipse LogoHave you been eclipsed lately? I mean software-wise, of course, using the Eclipse integrated development environment (IDE). Today I came pretty close to feeling eclipsed by the latest Eclipse download dubbed “Europa”. It began with the sheer size of the packages. 125 MB for the Eclipse JEE Europa version, 36 MB for web tools, another couple of megabytes for PHP development tools, visual editor, etc., etc. Not a problem with today’s DSL, you might think, and that is of course true if you live in America or Europe.

Unfortunately it’s a different story in Thailand. The Eclipse download page insisted on assigning a local mirror to me. This may be well-intentioned, alas not very effective, because servers located in Thailand tend to be bandwidth-drained, especially if it belongs to a public institution. Regrettably, there was no way to change that. The first connection delivered a whopping 4 kb/s download speed and stalled after 15 minutes. After that I decided to switch to BitTorrent. The BitTorrent software gave me 5 kb/s. That’s still dial-up speed, but at least a small improvement.

My computer spent the night downloading Eclipse files.In the morning, all the precious nuggets had arrived on my hard disk. Installation was a breeze compared to the download. Most of the standard components were already included in the Java EE download. I just had to add WTP, PDT, and a few other favourites on top of the Europa distro. In the past, this wasn’t always an easy task. I remember the time when some plugins depended on different, mutually incompatible versions of other plugins. The plugin architecture of the Eclipse framework is sort of asking for this type of problem.

Fortunately the days of dependency hell are gone thanks to synchronised update cycles of the Eclipse projects (there are 21 individual modules in the Europa release). In just a few minutes I had my shiny new Eclipse up and running. After starting it with the “-clean” parameter over the old workbench directory I was in business. It even accepted my old configuration settings. The thing I noticed first is that Europa launched considerably faster than my previous 3.2 version, but -good gracious- the title bar displayed “Program not responding” when I tried to interact with the menu. It seems that Eclipse is now initialising UI components after showing the IDE window and it keeps UI components locked during that time. Eventually after 10 seconds or longer, the program worked normally. I suspect that Eclipse is not loading faster after all; it just displays faster. The second surprise was that Eclipse opened external editor when I double-clicked on a JavaScript file in the navigator. What on earth? I thought I had WTP installed, which supposedly includes a JavaScript editor. Instead of getting to the bottom of that question, I decided to install my favourite JavaScript editor JSEdit, which now belongs to Adobe, but is still distributed freely. Eclipse IDE

Since I use Eclipse for Java as well as PHP development, I gave the new PHP Development Tools (PDT) a spin. PDT is now dubbed the premier PHP editor for Eclipse. To be honest, I was mildly disappointed. First of all, the outline view did not work. While syntax colouring and code folding were okay, the PDT editor lacks some of the features that I have grown used to, such as automatic code completion, marking of uninitialised local variables (which is great for typos in variable names), occurrence highlighting, instant compilation, etc.

Since all of these are real productivity gainers, I quickly reverted back to my old PHPEclipse plugin, after playing with PDT for a while. Because PDT is work in progress, I will certainly check back in a few months. The major incentive to use PDT instead of PHPEclipse is the integration of PDT with the Zend debugger plugin. What else is new in Eclipse? The interface now uses a gradient colour scheme which gives the UI a nice new look. Java code editing and refactoring has been improved. Code completion recognises Java types even if the respective imports haven’t been typed out yet. The code assist function is now able to to determine the legal types of exceptions in a catch clause based on the contents of the try block.

Unused members and types are now detected, and refactoring can be invoked from the context menu, which makes repetitive tasks, such as renaming identifiers, really easy. Though all of these are small incremental improvements, overall the JDT has become more intelligent as well as faster, which I am sure, every Java developer will appreciate. Of course, there are many more new features, in fact too many to list them here. In summary, Europa is definitely worth the download, even if you should feel a little “eclipsed” by the number and size of its of modules.