Workspace optimization

Why bother?

One of the strengths of working through Maven is that you can easily compile and run a Web application on the command line. That’s invaluable as a foundation, but your day-to-day programming will go a lot faster if you can compile, run, and debug your application within an IDE.

Fortunately, Maven integrates with development environments so you don’t have to set things up twice.

Eclipse

The simplest and most efficient setup is to have Maven generate an Eclipse project file for your projects. This allows Eclipse to compile your sources in the background, which it is going to do anyway, while adhering to the Maven 2 directory structure. The first step is to add a Maven repository variable to your workspace with a command like this one:

mvn -Declipse.workspace=/home/me/workspace eclipse:add-maven-repo

Then download available library sources and create the project metadata for Eclipse:

mvn -Declipse.downloadSources=true eclipse:eclipse

Import the project to your Eclipse workspace. Its dependencies, source, and target directories will be ready to go. When you upgrade to a new version of Databinder or add other dependencies to your pom.xml, you’ll need to rebuild the Eclipse project:

mvn -Declipse.downloadSources=true eclipse:clean eclipse:eclipse

Eclipse plugins

To run your Web application in Eclipse, you’ll need a plugin such as Jetty Launcher. It requires an installation of Jetty 5, that being the expanded Jetty download dumped anywhere on your hard drive. (Jetty 6 is still beta, and not supported by the launcher.) Follow the Jetty Launcher quickstart to get things running.

Amateras HTML Editor is an HTML editor plugin with syntax folding and an almost-live preview. (Turn on the preview pane in preferences; it will update after every save.) Amateras’s install is a little tricky so you may want to postpone it until you’re working heavily in HTML.

When you do have it installed, turn off HTML syntax validation in the Amateras tab of your project preferences, as it will red-flag every instance of “wicket:extend,” etc.

NetBeans

NetBeans includes a servlet container (Tomcat), and an HTML editor that’s almost as good as Amateras. Because it uses Swing instead of SWT, it looks and feels much better than Eclipse on Mac OS X, much worse than Eclipse on Linux, and about the same on Windows.

To integrate with Maven 2, install the Mevenide2 plugin via the Update Center, as described part-way down this page. After restarting NetBeans, it is trivial to open and run a Databinder project, which will deploy into Tomcat automatically.

This method uses Maven to build the project, which is more capable than the internal build Eclipse will perform with a project generated by eclipse:eclipse, but also much slower. Furthermore, hot fixing code (“Apply Code Changes”) is unavailable. If you like to code, test, and fix at the same time, then you’re better off with Eclipse+Jetty.

MySQL defaults

MySQL, though it's finally a grown-up database server, has defaults from the 1990s. If you don't change them Hibernate will create your tables in a Latin1, MyISAM shantytown.

It's possible to change these settings within Hibernate, or you can change the defaults in MySQL. This is done in the my.cnf file, which is often in /etc or /etc/mysql, or in some path with capital letters and spaces for Windows. If this file exists, find its [mysqld] section. If it doesn't exist, you can create it with only the [mysqld] section.

[mysqld]
default-character-set=utf8
default-table-type=InnoDB

You will need to restart the MySQL server, and it's best to drop databases and start over completely. Following that you should be able to rollback transactions and insert Chinese characters without issue.

Warning: Some applications (often in PHP) assume the standard MySQL defaults are in place and will fail otherwise. As always, be careful when making changes to an active Web server.

Any lasts requests?

With your IDE tweaked-out and ready to go, it’s time to stop configuring and start programming. Read through the examples if you haven’t already, and try running them locally. Each one uses a different database, as described in its hibernate.properties.

When you add annotated classes to your Hibernate configuration, tables to hold them and their mapped properties will be automatically created as your application is starting up. Tables and columns will never be deleted, so drop them or the entire database yourself whenever you want a fresh start.

As soon as your own application goes outside the conceptual bounds of the examples, you’ll probably run right into some transient object and property not found exceptions. Take a pit stop at Databinder 101 and call us in the morning.

Now go pop a wheelie. If you skin your knees, we’ll help you out on the forum.