“The time has come…to talk of many [technologies].” –Lewis Carroll(‘The Walrus and the Carpenter’)
Java
Installing Sun Java SE 6, Maven 2 and Tomcat 5.5 on Fedora GNU/Linux
Oct 5th
For using most of the enterprise technologies based on Java, you generally need at least the following components installed and configured on your system:
- Sun Java SE (or EE) SDK
- A command line build tool like Ant or Maven
- A Java application server/container like Tomcat, Jetty, Glassfish, JBoss etc.
Based on which 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 be able to work with all Java technologies, 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 in future.
Installing OpenJDK/Sun Java SE 6, Apache Maven 2 and Tomcat 5 on Fedora GNU/Linux
Installing Java SE 6
You can’t install Sun’s JDK directly from the Fedora repositories, you have the following two choices:
- Use OpenJDK that comes installed by default in Fedora 9(if not, you can install it with a simple ‘yum install java-1.6.0-openjdk’ command; or first search for the exact package name using ‘yum search jdk’). If you want to go with Fedora’s OpenJDK then you don’t have to do anything else, except perhaps set JAVA_HOME environment variable to OpenJDK installation path in your profile file.
- Install Sun’s latest JDK by manually downloading the binaries from Sun’s website. If you are very specific about using Sun’s official JDK only, then you first have to un-install OpenJDK that is installed by default in Fedora 9. Then you need to download Sun’s JDK and run the installer. (Download the Java EE SDK if you want to install the enterprise edition.) Assuming you have downloaded Sun JDK binary and saved it in your home directory under a name like jdk-6u7-linux-i586.bin, run the following commands to complete the installation:
# yum remove java-1.6.0-openjdk java-1.6.0-openjdk-plugin
# yum install compat-libstdc++-33 compat-libstdc++-296
# cd ~ & chmod +x jdk-6u7-linux-i586.bin
# ./jdk-6u7-linux-i586.bin
# javac -version
javac 1.6.0_07As a final step, add the following line to your profile file(e.g. .bash_profile) to set the JAVA_HOME environment variable to the path where you have installed Sun JDK:
export JAVA_HOME /opt/jre/jdk
Make JAVA_HOME point to OpenJDK installation path if you are using OpenJDK.
Installing Apache Maven2
Apache Maven 2 can be installed using yum command:
# mvn ––version
Maven version 2.0.4
# yum remove maven2
Installing Maven 2 on Fedora 9 using the yum package manager gave me the old 2.0.4 version, so I removed it and decided to install Maven manually. To manually download and extract Maven 2 archive on Fedora 9, follow these instructions:
- Download the latest stable version of Apache Maven 2 archive from its download page.
- Extract it to your home directory and rename the directory to ‘maven2′
# tar xjvf apache-maven-2.0.9-bin.tar.bz2
# mv apache-maven-2.0.9-bin maven2 - Add the following line to your profile file(e.g. .bash_profile or /etc/profile) to set maven2 executables in system path:
export PATH=$PATH:$HOME/maven2/bin
- Confirm if Maven 2 is installed and configured correctly:
# source .bash_profile
# mvn ––version
Maven version 2.0.9
Java version 1.5.0
Installing Tomcat 5 and Jetty
You can finally install tomcat and jetty servers using yum command:
The installation procedure on other GNU/Linux distributions should be on similar lines using their respective package managers and I will try to post the procedure for Ubuntu, Gentoo, openSuse and Mandriva distributions in the near future.
Testing the installation
To test the above installation, see my next post(to be published), “Hello, World” Java Web Application using Java SE 6 + Tomcat 5.5 + Maven 2.”
Installing Sun Java SE 6, Apache Maven 2 and Tomcat 5.5 on Windows OS
Aug 22nd
For using most of the enterprise technologies based on Java, you generally need at least the following components installed and configured on your system:
- Java SE or EE SDK
- A command line build tool
- 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.
- 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).

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

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):
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.

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:

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

Add %M2% to the Path variable.

Check Maven 2 Version and Confirm Install
To check if Maven is properly configured or not, start a command prompt and check its version:
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).

Create Tomcat Environment Variables
Next we need to add the required environment variables.
- Edit the Path environment variable and add the path to Tomcat’s bin directory to it.

- 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.

Check Tomcat Version and Confirm Install
Verify Tomcat’s installation by running the following commands in the Windows command prompt:
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
Aug 20th
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
- Download and install the latest version of Sun JDK: Sun Java SE 6.
- Download and install Apache Tomcat web application server: Apache Tomcat 5.5.
- 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.

Creating a New Struts 2 Web Application Project in IntelliJ IDEA 8 M1
- 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.

- 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.

[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).

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.
- 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.
You can accept the default settings for everything else in the wizard. Click Finish.
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
- Right-click on the src folder, select New -> Class and enter hello.HelloWorld in the New Class dialog box.

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] - 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] - 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.
- The HelloWorld web application project structure, when relevant folders are expanded, should now look like this:

(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
- 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.

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.
You should now see a warning displayed near the bottom of the window and the option to fix it.

Click the Fix button on the far right corner and then click OK.
- 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:


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:
- more details on Struts 2 support in IntelliJ IDEA 8.0.
- the full list of features introduced in IntelliJ IDEA 8.0 Milestone 1 and what is planned for the final release.
Struts 2 Plugin for NetBeans IDE – nbstruts2support
Aug 4th
As mentioned in my previous post about creating Struts 2 web applications in NetBeans IDE, there is a Struts 2 plugin available for the NetBeans IDE but it is still under development. You can try it out right away if you are interested; the name of the plugin is nbstruts2support.
First read the summary of its current feature list(and what is planned for the future) and have a look at some screenshots. Then follow the installation instructions and try it on your system.
Below I take you through the installation process of nbstruts2support Struts 2 plugin for NetBeans 6.1 IDE showing a few screenshots along the way.
Installing nbstruts2support plugin in NetBeans IDE
- Go to the nbstruts2support download page and download the two nbm files and save them in a directory.
- Start the NetBeans IDE if not already running and go to Tools -> Plugins and select the Downloaded tab. Click the Add Plugins… button and select the two plugin files(.nbm files) downloaded in the earlier step.

- The Plugins dialog box should show you the details about the plugin.

Go through the wizard clicking the button Next and accepting the license agreement and ignoring any errors about invalid signature.

Restart the NetBeans IDE when prompted.

The Struts 2 plugin is now installed in NetBeans.
Using nbstruts2support in NetBeans IDE
- The plugin doesn’t allow a Struts 2 project template to be created in NetBeans, which means that we need to manually create a basic Web Application and add Struts 2 libraries to it manually. We also need to create struts configuration files(struts.xml and struts.properties) and modify the web.xml file. If we do all this manually, then what does the plugin do?
For one thing, the plugin helps in creating template files for Struts 2 Actions, Interceptors, Results etc.

Secondly, it helps in auto-completion:

More information on auto-completion.It is not yet completely bug free though:

It also helps in easy navigation using hyperlinks. (See all the tabs at the top of the page: Analysis, Phase I, Phase II, Phase III.)

[image from nbstruts2support website]
End Notes:
The current state of Struts 2 support in the NetBeans IDE is hardly satisfying. Let us wait and see how much time it takes to complete at least the basic features in nbstruts2support. It is at least slightly better than creating and developing Struts 2 applications completely manually.
The state is different if we look at other IDEs like Eclipse and IntelliJ IDEA. I will talk more about Struts 2 support for Eclipse IDE in my next post.
“Hello, World” Web Application using Struts 2 in NetBeans IDE 6.1
Jul 30th
This tutorial guides you through the process of creating and running a basic “Hello, World” Struts 2 web application using the NetBeans IDE 6.1.
NOTE: I recommend trying to follow the NetBeans tutorial on the Struts 2 website first. If you find any problems following it, then come back to my tutorial. I have tried to make this more beginner friendly by including a lot of screenshots.
Download/Install Java SE, NetBeans and Struts 2
- Download and Install the latest version of Sun JDK: Sun Java SE 6 Update 7.
- Download and Install the latest version of NetBeans IDE: NetBeans IDE 6.1.
- Download the Struts 2 “Full Distribution” package(~90MB) and extract it in a directory. You can also opt for the smaller “Essential Dependencies Only” package if you want to later incrementally add additional packages as and when the need arises.
- Run the NetBeans IDE and create a new Web Application project in it. Name it “HelloStruts2World” or something like that.

Don’t select any frameworks, especially Struts 1.2.9, to be added to the project.
Add Struts 2 Libraries to Web Application project in NetBeans and configure web.xml file
- Add the Struts 2 library files to the web application project: Expand the web application project structure in the Project pane if not already expanded; right-click on the Libraries folder and click the Add JAR/Folder… menu item.

In the Add JAR/Folder file chooser dialog box, browse to the extracted Struts 2 directory, go to lib directory in it and select all the JAR files that you want to add to the project. Hold down the Ctrl button to select multiple files.

The following JAR library files are essential for most Struts 2 projects(and for this tutorial) but you can select more if you know that you need them(you can add additional libraries later also):
- commons-logging
- ognl
- struts2-core
- xwork
- freemarker
Libraries folder in your project will now look like this:

- Add a filter element to web.xml deployment descriptor to let Struts 2 handle all the requests for your web application. Expand the Configuration Files folder and double-click on web.xml file, select the XML tab and copy paste the following code in it.
[xml]
Struts 2 filter
org.apache.struts2.dispatcher.FilterDispatcher
Struts 2 filter
/*
30
[/xml]You can enter the same data in Filters tab also:
Create Struts 2 action Java class and JSP result page and configure struts.xml file
- We need one or more Java packages to store all the Java classes(Struts 2 actions) in it. Let’s call the first package “hello.” Right click Sources Package directory, select New and then select Java Class… menu item. Enter a name for the Java class(say HelloStruts2World”) and enter a package name(say hello) and click Finish.
- Edit the HelloStruts2World.java file so that it looks like this:
[java]
package hello;
import com.opensymphony.xwork2.ActionSupport;public class HelloStruts2World extends ActionSupport {
private String userName;
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}private String message;
public String getMessage() {
return message;
}@Override
public String execute() {
message = “Hello, ” + userName + “.”;
return SUCCESS;
}
}
[/java] - We now need to configure the Java class created in the above step as a Struts 2 Action and map it to a result page. To do so, we need to create two Struts 2 configuration files – struts.xml and struts.properties – in the source package.
- Right-click on hello package in Source Packages folder and select New and then select XML document… and enter struts as the file name. This will create struts.xml file.
- Right-click on hello package in Source Packages folder and select New and then select Properties File… and enter struts as the file name. This will create struts.properties file.
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]This maps the requests sent to the “/HelloStruts2World.action” url to HelloStruts2World.java Struts 2 action and after the successful execution of the request, it gets directed to the index.jsp result page. Leave the struts.properties file empty for now.
- Let us access the message property set by HelloStruts2World action and display it in the index.jsp page. Edit index.jsp so that it looks like this:
[html]
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
"http://www.w3.org/TR/html4/loose.dtd">
Hello World!
Struts 2 Message:
Enter your name:
[/html]
Run the Struts 2 Web Application Project in NetBeans 6.1 IDE
- The “HelloStruts2World” web application project structure, when relevant folders expanded, should look like this:

- Run the web application by going to Run -> Run Main Project and then access the following URL in a web browser: http://localhost:8080/HelloStruts2World/. You may have to modify this URL depending on what port the web server is running(“8080″) and what is the name of your web application(“HelloStruts2World”).
Other Options:
This is the manual way to develop Struts 2 web applications in the NetBeans IDE but it is at least more beginner friendly than working from the command line using just the Maven build tool. There is a Struts 2 plugin called nbstruts available for NetBeans; its functionality is currently limited but it is under active development. Other popular alternative IDEs for developing web applications using Struts 2 are Eclipse and IntelliJ IDEA.
