Installing Sun Java SE 6, Apache Maven 2 and Tomcat 5.5 on Windows OS

6

For using most of the enterprise technologies based on Java, you generally need at least the following components installed and configured on your system:

  1. Java SE or EE SDK
  2. A command line build tool
  3. A Java application server/container like Tomcat, Glassfish, JBoss etc.

Based on the Java based technology/framework you want to use, you may need to install further dependencies. Even though you may not need all the three components mentioned above to work with every Java technology, I found myself installing them way too many times when compared to any other Java component that I wanted a place to document the installation process of these three components specifically, if only to refer to this post from other Java tutorials.

Below I explain how to install Java SE 6, Apache Maven 2 and Apache Tomcat 5.5 software.

Installing Sun Java SE 6 on Microsoft Windows

Download Java SE 6

Download and install the latest version of Java SE(currently JDK 6 update 7). Just run the installer and follow the wizard. Note the installation directory where the wizard installs the Java package(default will be C:\Program Files\Java). You then need to set the two environment variables JAVA_HOME and PATH.

Create Java Environment Variables

Go to Control Panel -> System -> Advanced System Settings and click the “Environment Variables” button. Or Control Panel -> System, select the Advanced tab and click the “Environment Variables” button if you are using Windows XP.

  1. Click the New… button below the System variables pane and add a new environment variable called JAVA_HOME and set it to the path to your Java installation directory(e.g. C:\Programming Files\Java).

    Set Java environment variable JAVA_HOME in Windows Vista and XP

  2. Select the Path variable in System variables pane and add the path to Java bin directory to it.

    Set Java environment variable PATH in Windows Vista and XP

Check Java Version and Confirm Install

Let us confirm the correct configuration of Java installation from the command line. Close all the open dialog boxes and start a new command prompt(Start/All Programs -> Accessories -> Command Prompt). Run the following commands in it(doesn’t matter what your current directory is):

$ echo %JAVA_HOME%
C:\Program Files (x86)\Java\jdk1.6.0_06
$ javac -version
javac 1.6.0_06

If you get an error saying that the ‘java’ command is not recognised or is not available, then you need to check the values the above environment variables were set to once again.

For more details, refer to Sun’s instructions on how to install Java SE.

Installing Apache Maven 2 on Microsoft Windows

Download Maven 2

Download the latest stable version of Maven from Apache Maven Project website. Extract it to a directory and rename the installation directory to maven. I assume Maven is now located in c:\maven.

Download Apache Maven 2 package from its website.

Extract the downloaded Apache Maven 2 compressed package to a directory.

Create Maven 2 Environment Variables

Create a new M2_HOME environment variable. Click the New… button(below System Variables pane) and enter the details as follows:

Set Apache Maven 2 environment variable M2_HOME in Windows Vista and XP

Similarly create another environment variable called M2 and set it to the value %M2_HOME%\bin

Set Apache Maven 2 environment variable M2 in Windows Vista and XP

Add %M2% to the Path variable.

Add Apache Maven 2 bin directory to environment variable PATH in Windows Vista and XP

Check Maven 2 Version and Confirm Install

To check if Maven is properly configured or not, start a command prompt and check its version:

$ echo %JAVA_HOME%
C:\Program Files (x86)\Java\jdk1.6.0_06
$ mvn –version
Maven version: 2.0.9
Java version: 1.6.0_06

For more details, refer to instructions on Maven’s website on how to install Maven 2.

Installing Apache Tomcat on Microsoft Windows

Download Tomcat 5.5

Download Apache Tomcat 5.5(or any other version of your choice) and extract the package in a directory(say C:\tomcat).

Download Apache Tomcat Java application server 5.5 or 6.

Create Tomcat Environment Variables

Next we need to add the required environment variables.

  1. Edit the Path environment variable and add the path to Tomcat’s bin directory to it.

    Add path to Tomcat's bin directory to environment variable PATH in Windows Vista and XP.

  2. Create a new environment variable called CATALINA_HOME and set it to the directory where Tomcat is installed. I had extracted the Tomcat package to c:\tomcat directory in earlier step, so I would set CATALINA_HOME to c:\tomcat.

    Create CATALINA_HOME environment variable and set it to path to Tomcat's home directory in Windows Vista and XP.

Check Tomcat Version and Confirm Install

Verify Tomcat’s installation by running the following commands in the Windows command prompt:

$ echo %JAVA_HOME%
C:\Program Files (x86)\Java\jdk1.6.0_06
$ echo %CATALINA_HOME%
C:\tomcat
$ version.bat

You will need to start and stop the tomcat service from the command line manually(or tools from other Java frameworks may do that for you automatically). But if you want to the tomcat server to start automatically when the operating service, you can install it as a Windows service. For more details, refer to instructions on Tomcat website on how to run Tomcat as a Windows service. I am not including those instructions here because I don’t run and don’t recommend running it as a service; YMMV.

“Hello, World” Web Application using Struts 2 in IntelliJ IDEA 8.0 M1

4

At last we have a Java IDE that ships with Struts 2 support built-in: no manual configuring the web applications to add Struts 2 support and no more hassles of finding and installing Struts 2 plugins.

JetBrains released IntelliJ IDEA 8 Milestone release 1 a week ago and the milestone version includes support for Struts 2 out-of-the-box(no plugins need to be installed) so that we can test the functionality right away. Any loose ends should be tied up by the time the final version is released.

Installing IntelliJ IDEA 8 M1 and Other Required Components

  1. Download and install the latest version of Sun JDK: Sun Java SE 6.
  2. Download and install Apache Tomcat web application server: Apache Tomcat 5.5.
  3. Download and install the 30-day trial version of the latest IntelliJ IDEA 8 version; currently Milestone 1 is available, but when you read this, probably another milestone, or beta, or even the final version may have been released, so make sure that you download the most recent release of IntelliJ IDEA 8. I show the screenshots from Windows Vista operating system in this post but it should work similarly for Mac and GNU/Linux too.

    Download 30-day trial version of JetBrains IntelliJ IDEA 8.0 Milestone 1 Java IDE with Struts 2 Support.

Creating a New Struts 2 Web Application Project in IntelliJ IDEA 8 M1

  1. Run IntelliJ IDEA 8 M1 IDE and create a new project by going to File -> New Project… and following the wizard: Enter a name for the application(say “HelloWorld”) when prompted and make sure you select Web Application and Struts 2 checkboxes on the technologies page.

    Select Web application support and Struts 2 framework support when creating a new project in IntelliJ IDEA 8.0 IDE.

  2. You can accept the default settings for everything else in the wizard. Click Finish.

  3. When you click Finish, IntelliJ IDEA will start downloading the required Struts 2 JAR library files to your project’s lib directory, which may take a few minutes. IntelliJ IDEA may then parse all the files in the project to be able to help you later when you start editing/browsing the files.

    IntelliJ IDEA 8.0 IDE downloads the Struts 2 JAR libraries automatically when creating a new Struts 2 project.

    [The annoying thing is that IntelliJ downloads these Struts 2 library files for every Struts 2 application you create. Currently there is no option to reuse the previously downloaded library files. Hope they add it in the final version.]

    You should finally see the project structure created as shown below(expand the directories as needed).

    Struts 2 Web Application project structure in IntelliJ IDEA 8.0 IDE.

    As you can see, the required Struts 2 libraries are automatically downloaded and installed in the lib directory(and included in the build path) by the IDE.

  4. You can also see that the IntelliJ IDEA IDE has created and placed the struts.xml configuration file(containing basic template text) in the src directory. The generated web.xml file includes the following configuration elements needed by the Struts 2 framework so that you don’t have to type or copy/paste it manually in every Struts 2 web application:
    [xml]

    struts2
    org.apache.struts2.dispatcher.FilterDispatcher


    struts2
    /*

    [/xml]
    You can add additional configuration elements to the file.

The basic structure needed for a Struts 2 web application project is now in place and we only ran the New Project wizard in Intellij IDEA so far! This is far cry from the experience with NetBeans or Eclipse IDEs even with the help of the plugins: see my previous posts “Hello, World” Web Application using Struts 2 in NetBeans IDE 6.1 and Struts 2 Plugin for NetBeans IDE – nbstruts2support for example. All we need to do now is to write our own application logic.

Let us create an example action class in Java and a JSP result page to go with it.

Create Struts 2 action Java class and JSP result page and configure struts.xml file

  1. Right-click on the src folder, select New -> Class and enter hello.HelloWorld in the New Class dialog box.

    HelloWorld Struts 2 Java action class for Struts 2 web application in IntelliJ IDEA 8.0 IDE.

    Edit the file so that it contains the following code.
    [java]
    package hello;

    public class HelloWorld {
    private String userName;
    public String getUserName() {
    return userName;
    }
    public void setUserName(String userName) {
    this.userName = userName;
    }

    private String message;
    public String getMessage() {
    return message;
    }

    public String execute() {
    message = “Hello, ” + userName + “.”;
    return “SUCCESS”;
    }
    }
    [/java]

  2. Let us access the message property set by HelloWorld action and display it in the index.jsp page. Edit index.jsp so that it looks like this:

    [html]
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    <%@ taglib prefix="s" uri="/struts-tags" %>




    Struts 2 Message:


    Enter your name:




    [/html]

  3. We now need to configure the Java class(HelloWorld.java) as a Struts 2 Action and map it to the Struts 2 Result page(index.jsp) created in the above steps. Edit struts.xml file such that it has the following content:

    [xml]
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">


    /index.jsp

    [/xml]
    (Ignore the error shown by IntelliJ IDEA in struts.xml file if it says it is not able to resolve struts-default package.)

    This maps the requests sent to the “/HelloWorld.action” url to HelloWorld.java Struts 2 action class, and after the successful execution of the request, it directs to the index.jsp result page.

  4. The HelloWorld web application project structure, when relevant folders are expanded, should now look like this:

    Hello World Struts 2 web application project structure in IntelliJ IDEA IDE.

    (Did you notice how struts.xml was automatically moved to our hello package? Nice, huh?)

Create Run/Debug Configuration in IntelliJ IDEA and Run the Struts 2 Project

  1. Before we can run the application, we first need to create/edit the Run configuration for our project. Select the HelloWorld project in the left pane and go to Run -> Edit Configuration. If the left pane is empty, it means that we need to create a new configuration which is a one-time job; after creating it the first time, we can use the same configuration for all our future projects.

    Click the + button at the top of the window and select Tomcat -> Local (or other application server of your choice; I use Tomcat server as example in this post) from the pop-up menu.

    Configure Apache Tomcat application server in IntelliJ IDEA 8.0 IDE.

    In Run/Debug Configurations window, click the Configure button and in the popped-up Application Servers window click the [+ Add] button and select the directory where Apache Tomcat is installed on your system in Tomcat home and Tomcat base directory fields.

    Configure Run/Debug configuration for Struts 2 web application project in IntelliJ IDEA 8.0 IDE.

    You should now see a warning displayed near the bottom of the window and the option to fix it.

    Select Web project with Struts 2 Facet to deploy in IntelliJ IDEA 8.0 IDE.

    Click the Fix button on the far right corner and then click OK.

  2. We are now ready to run the application. Select the HelloWorld project in the left pane and go to Run -> Run…. You should see the run configuration window which allows you to make any further configuration changes before the application is run. (If you don’t want to see the configuration window every time you run the application, uncheck the “Display settings before launching” checkbox.)

    Click the Run button to run the application. You can see the result in the following screenshots:

    Output of HelloWorld Struts 2 web project in IntelliJ IDEA 8.0 IDE.

    Output of HelloWorld Struts 2 web project in IntelliJ IDEA 8.0 IDE.

    Happy developing with Struts 2 in IntelliJ IDEA 8!

Last Words

This is a big moment for the Struts 2 users. It’s a shame that after such a long period since the release of Struts 2 web framework, its support in all the popular IDEs is next to zero. The version of the NetBeans IDE that will be released next, version 6.5, talks nothing about the support for Struts 2 framework(you can see support for Struts 1.2.9 proudly displayed on NetBeans 6.5 Beta release page); all hopes are now pinned up on the nbstruts2support netbeans plugin I guess. I hope that IntelliJ IDEA’s out-of-the-box Struts 2 support will encourage the teams/communities of other popular IDEs to follow the suit.

Also see:

  1. more details on Struts 2 support in IntelliJ IDEA 8.0.
  2. the full list of features introduced in IntelliJ IDEA 8.0 Milestone 1 and what is planned for the final release.

How WordPress 2.6 ‘Post Revisions’ Retrieved My Unsaved Post Updates

0

The feature announced to be included in the next version of WordPress that had excited me the most was the Post Revisioning feature that was set for the WordPress 2.6 release. After having used 2.6 version for so many days, I finally had a taste of its usefulness today. (Even though I didn’t get to use it much until now, the peace of mind that you get to carry while editing the posts makes the feature worth every effort put in by the WordPress development team).

I did nothing strange on this occasion: while editing and saving and editing and saving and… a draft post, I opened another related, older post in a new browser tab and made a few changes to that post too. Just forgot to save it! I don’t remember when I had closed that tab as my focus was on my current draft post. When I opened the older post again after sometime, WordPress displayed a notice informing me that there is a newer auto-saved version of the post available:

Wordpress 2.6 warns about autosaved version of a post and allows restoring it through its new Post Revisions feature.

Auto-saving posts/drafts is old news. But near the bottom of the page, I could see the complete history of my edits, the relevant date and time information included:

Wordpress 2.6 warns about autosaved version of a post and allows restoring it through its new Post Revisions feature.

Clicking on “View the autosave” link(see the first screenshot above) took me to the automatically saved version of the page. Scrolling down the page took me to “Post Revisions” section where I could select the versions that I want to compare:

Wordpress 2.6 warns about autosaved version of a post and allows restoring it through its new Post Revisions feature.

And finally, I was able to view the two versions side-by-side to see the difference between the two versions visually(click the image to see the larger version):

Wordpress 2.6 warns about autosaved version of a post and allows restoring it through its new Post Revisions feature.

(Bonus: What happens if you compare the same versions of a post? WordPress 2.6 Easteregg!)

A click of a button switched the post to the autosave version(because that’s what I had wanted):

Wordpress 2.6 warns about autosaved version of a post and allows restoring it through its new Post Revisions feature.

And the post was restored:

Wordpress 2.6 warns about autosaved version of a post and allows restoring it through its new Post Revisions feature.

(I didn’t have to worry a lot when restoring because I can always go back to the earlier version because all the revisions are still there.)

Nothing that I didn’t know already but actually going through the process and being able to save those few edits that would have been lost into thin air(or difficult to restore) in earlier versions of WordPress was quite a bit of fun. The whole experience was seamless and tension-free.

Just sharing the excitement ;)

Posting to Identi.ca From Ubuntu 8.04 Using Gwibber Client

2

Instructions are available on the Internet on how to download and install Gwibber microblogging client(twitter/identica/etc.) on a Debian-based operating system. The Gwibber page on Ubuntu Wiki, for example, has a really long/detailed procedure to install it; below I have documented the quick and dirty procedure that has worked for me to install Gwibber on Ubuntu Hardy Heron distribution(it should work on other Debian-based GNU/Linux distributions with little modifications).

Quickets and dirtiest way:

# sudo apt-get install bzr python-simplejson
# cd $HOME
# bzr branch lp:gwibber
# sh gwibber/run

Go to Accounts -> Create to add your microblogging/social networking account details.

Gwibber Webkit Branch:

Guys on Identi.ca have been recommending installing the webkit branch of Gwibber, so below is a bit longer procedure to get this version of Gwibber installed.

  1. Install the Gwibber pre-requisites. Run the following command in a shell:
    # sudo apt-get install bzr python-cairo-dev python-simplejson
  2. Checkout the webkit branch of Gwibber source code on your machine:
    # cd $HOME
    # sudo bzr branch lp:~segphault/gwibber/webkitui
  3. Change the directory and run the Gwibber client:
    # cd webkitgui
    # ./run

  4. If all goes well, install it:

    # sudo python setup.py install

Go to Accounts -> Create to add your microblogging/social networking account details.

Some Gwibber Tips:

  • You can run Gwibber any time by pressing ALT-2 key and entering “gwibber” as command.
  • If you want to create a desktop shorcut, right-click on the desktop, click on “Create Launcher…” and enter “gwibber” in the command field.
  • If you want to see Gwibber in the desktop panel/tray, select the “Tray Icon” option from View menu.

Screenshots:

Here are a couple of screenshots of Gwibber connected to the Identi.ca microblog.
Gwibber for GNU/Linux supports Digg, Twitter, Facebook, Jaiku, Pownce, Flickr and Identica microblog and social networking web applications.
Gwibber for GNU/Linux supports Digg, Twitter, Facebook, Jaiku, Pownce, Flickr and Identica microblog and social networking web applications.

C++ Development Environment on Windows using Eclipse Ganymede and Nuwen MinGW

7

My friend alerted me a month ago about Nuwen’s build of MinGW toolchain that has version 4(currently 4.2.1) build of g++ compiler. Now that’s awesome. But that is not all: it also comes with C++ Boost 1.35 bundled as part of it, among many other useful C++ libraries.

Consider this post to be an update of my previous post “Setting Up C++ Development Environment on Windows with EasyEclipse and MinGW.” I will be using the following components in this post to setup the development environment for C++:

  1. Eclipse Ganymede for C++ instead of EasyEclipse for C++.
  2. Nuwen’s MinGW 3.9 Distro instead of official MinGW build.

Download/Install Eclipse Ganymede for C/C++ and Nuwen’s MinGW for Windows

  1. Download Nuwen’s MinGW distro and extract it in a directory. Try to extract it in a directory that doesn’t contain spaces or special characters in it: a good place to extract will be C:\MinGW.
    Download Nuwen's MinGW distribution.

    Extract Nuwen's MinGW distribution in a directory.

  2. Download Eclipse Ganymede IDE for C++ and extract it a directory.
    Download Eclipse Ganymede for C/C++ IDE.

    Extract Eclipse Ganymede for C/C++ in a directory.

  3. Run the Eclipse executable from the directory where you have extracted it(you can later place a shortcut to the Eclipse executable on the windows desktop/start menu/quick launch bar/etc. for quick access). When you try to create a new C++ project in Eclipse, MinGW will be automatically detected and be listed as one of the available toolchains. Automatic detection works the best if you extract in the directory as recommended in Step 1.

    Select installed Nuwen's MinGW toolchain when creating new C/C++ projects in Eclipse Ganymede for C/C++ IDE.

  4. You can check the version of the g++ compiler from the command prompt.
    C:\> cd C:\MinGW\bin
    C:\> g++ -v
    gcc version 4.2.1-dw2 (mingw32-2)

    (You don’t have the change the working directory to MinGW bin directory if its location is in the PATH variable.)

  5. Let’s write some C++ code making use of a Boost library and try compiling the code. Here is a screenshot of an example HelloWorld program(click to see the large version):

    HelloWorld C++ application in Eclipse IDE using Nuwen's MinGW distro.

It’s such a good thing for me to have discovered a MinGW build with g++ v4 and Boost bundled in it at around the same time that Eclipse Ganymede was released, I have to thank Stephen T Lavavej for bringing the C++ development experience on Windows a bit closer to that of GNU/Linux. Head to Nuwen’s MinGW page to learn what all is included in the distribution. You may also be interested in my previous post that I referred to at the beginning of this post.

Now for some more paying with the g++ 4.2.1 compiler on Windows ;)

Go to Top