Struts 2 Plugin for NetBeans IDE – nbstruts2support

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

  1. Go to the nbstruts2support download page and download the two nbm files and save them in a directory.
    Download nbstruts2support Struts 2 plugin for NetBeans IDE.
  2. 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.
    Install nbstruts2support nbm plugin files in NetBeans IDE.
    Install nbstruts2support nbm plugin files in NetBeans IDE.
  3. The Plugins dialog box should show you the details about the plugin.

    Install nbstruts2support nbm plugin files in NetBeans IDE.

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

    Install nbstruts2support nbm plugin files in NetBeans IDE.

    Restart the NetBeans IDE when prompted.
    Install nbstruts2support nbm plugin files in NetBeans IDE.

    The Struts 2 plugin is now installed in NetBeans.

Using nbstruts2support in NetBeans IDE

  1. 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.
    nbstruts2support Struts 2 plugin for NetBeans IDE allows easy creation of Struts 2 Action, Interceptor etc. template files.

    Secondly, it helps in auto-completion:
    nbstruts2support Struts 2 plugin for NetBeans IDE helps in auto-completion.
    More information on auto-completion.

    It is not yet completely bug free though:
    nbstruts2support Struts 2 plugin for NetBeans IDE helps in auto-completion but is not bug free.

    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.)
    nbstruts2support Struts 2 plugin for NetBeans IDE helps in hyperlinking.
    [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

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

  1. Download and Install the latest version of Sun JDK: Sun Java SE 6 Update 7.
  2. Download and Install the latest version of NetBeans IDE: NetBeans IDE 6.1.
  3. 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.

    Download Struts 2 Full Distribution or Dependecy Only package.

  4. Run the NetBeans IDE and create a new Web Application project in it. Name it “HelloStruts2World” or something like that.

    Create a new web application project in NetBeans.

    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

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

    Add Struts 2 JAR library files to NetBeans Web application project.

    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.

    Add basic Struts 2 JAR library files to NetBeans Web Application project.

    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:

    Struts 2 JAR files added to Libraries folder of web project in NetBeans.

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

  1. 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.
  2. 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]

  3. 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.
    1. 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.
    2. 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.

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

  1. The “HelloStruts2World” web application project structure, when relevant folders expanded, should look like this:

    Hello World Struts 2 web application project structure in NetBeans IDE.

  2. 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”).

    Struts 2 Action redirects to JSP "SUCCESS" result page

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.

Witty Twitter + Darrel’s Identi.ca patch = Witty Identi.ca Client

Witty Identi.ca Client?

Finally found some time to play with Darrel Miller’s Identi.ca patch for Witty Twitter client. Good news: it works.

Witty Twitter client patched for Identi.ca.

If you want to try it too, this is what I did:

  1. Checked out the source code of Witty Twitter client using TortoiseSVN subversion client on Windows Vista.
  2. Downloaded Darrel Miller’s Identi.ca patch for Witty.
  3. Applied the patch using TortoiseSVN(no patch/cygwin tools for Windows needed!).
    (I got errors related to ITweet.cs in the patch file, so I edited it manually; http://ur1.ca/0tx. Use my modified patch file if you get similar errors.)
  4. Built the patched Witty source code in Microsoft Visual C# Express Edition 2008(with no configuration changes).
  5. Ran Witty(from “Release” directory), entered Identi.ca login details(alas, you are out of luck if you use only OpenID based login), and there I have all my contacts’ Identi.ca messages :)
  6. I can upload the patched source code/built binary files somewhere if anybody wants to play with it without going through the patching/building business.

So this is fun.

Additional information:
What is Witty: “Witty is a free, open source Twitter client for Windows Vista and XP powered by the Windows Presentation Foundation (WPF). ”

What is WPF: “Windows Presentation Foundation (WPF) provides developers with a unified programming model for building rich Windows smart client user experiences that incorporate UI, media, and documents.”

What is Identi.ca: “Identi.ca is a micro-blogging service based on the Free Software Laconica tool.”

Setting Up Rails Development Environment on Ubuntu GNU/Linux

This is an adaptation to Ubuntu GNU/Linux platform of my previous post which was meant for the Windows platform: Setting Up Rails Development Environment on Windows Vista/XP

I can think of two different ways in which you might want to set up a development environment for Ruby on Rails on a GNU/Linux machine. One is to download everything outside of the package manager of your distribution i.e. build everything from the source. I am going to cover the second, easier way: how to setup Rails on a Debian/Ubuntu machine using its package manager for the most part. I show below how to setup Ruby, RubyGems, Rails, Mongrel, MySQL, and Subversion as part of the development stack.

  1. Installing Ruby:

    If not already installed, install the build-essential package first:

    # sudo aptitude install build-essential

    Then install the Ruby and related packages:

    # sudo aptitude install ruby irb ri rdoc rake libopenssl-ruby libsqlite3-ruby ruby1.8-dev
  2. Installing Rubygems

    Though it is possible to install Rubygems using the Ubuntu package manager, not only will you get an old version of rubygems if you do so, it also may not be compatible with the latest version of rails. I strongly recommend you download the source code package of the latest version of rubygems and install it using its setup script:

    # cd $HOME
    # wget http://rubyforge.org/frs/download.php/38646/rubygems-1.2.0.tgz
    # tar xvzf rubygems-1.2.0.tgz && cd rubygems-1.2.0
    # sudo ruby setup.rb

    Debian purists may frown at installing packages all over the system directories outside of control of the package manager. See Debian’s position on Rubygems. [via - RailsOnUbuntu]
    Remember to download the latest version of rubygems available(currently 1.2.0). You can remove the downloaded tgz archive and the extracted directory after the installation is finished.

    #cd $HOME
    # rm -r rubygems-1.2.0.tgz rubygems-1.2.0

    If Ubuntu complains that the ‘gem’ command is not found, you may have to create a symbolic link like this:

    # sudo ln /usr/bin/gem1.8 /usr/bin/gem

    You can update the rubygems package by running the following command:

    # sudo gem update ––system
  3. Installing Rails

    The final step is to install the Rails gem package itself.

    # sudo gem install rails

    This will install the latest Rails version on your Ubuntu GNU/Linux. If you ever want to update Rails in the future, just run the following command:

    # sudo gem update rails

    You can update the other packages using Ubuntu’s package management tools(aptitude) since that is how you installed those packages in the first place.

The basic Rails development environment is now installed on your system and you can skip the rest of the post if you are happy with WEBrick as the web server, SQLite as the database server and your favourite text editor/IDE that may be already installed on your system. The following instructions cover installing an alternate web server called Mongrel; MySQL database server and its GUI tools; and Subversion.

  1. Installing Mongrel

    Installing the Rails gem also installs the WEBrick web server which is ideally suited for development purposes. Another much recommended web server for Rails development as well as production environment is the Mongrel web server. To install the Mongrel web server, run the following gem command:

    # sudo aptitude install mongrel

    After installing Mongrel, Rails automatically starts the Mongrel instead of WEBrick web server when you run the Rails applications in development mode. (Refer to Mongrel documentation to know more about runing Rails applications under Mongrel in production mode.)

  2. Installing MySQL

    This step covers the installation of MySQL database server and its GUI tools. Skip this step if you want to use some other database server. Run the following command to install the required mysql packages:

    # sudo aptitude install mysql-server mysql-admin mysql-query-browser

    One important step during the configuration process is to select a root password(you will need to enter it in the database.yml configuration file of your Rails application).

  3. Installing Subversion

    Finally, install your favourite revision control software – CVS, Subversion, git etc. You can install subversion in this way:

    # sudo aptitude install subversion

Now you can create/checkout Rails applications, edit the files using your favourite text editor/IDE and run it under Mongrel. In future, I will try to write about developing Rails applications using integrated development environments like Eclipse and NetBeans.

Installing Grails in Ubuntu GNU/Linux Using Package Manager

In my previous post I talked about setting up Grails development environment in GNU/Linux distributions by manually downloading the packages and configuring the environment variables. The main advantage of this method is that you can work with the latest versions of the Groovy and Grails packages available, and in fact, you can work with more than one version of these software at the same time: just point your environment variables to different locations. The procedure is also more or less independent of a particular GNU/Linux distribution.

An easier, alternative way to install Groovy and Grails packages is to use the package management system of your favourite GNU/Linux distribution. The trade-off is that you have to accept the version of the packages that are available in your distribution’s repositories(apt-get) or you may have to compromise with the stability of your system(dpkg). Below I am documenting the procedure to install Grails development environment using package manager tools in Ubuntu 8.04(Hardy Heron).

  1. Installing Sun JDK 6 in Ubuntu 8.04 Using apt-get/aptitude

    In Debian/Ubuntu based operating systems installing new packages is as simple as running aptitude command with the package name.

    # sudo aptitude install sun-java6-jdk

    You also need to set JAVA_HOME environment variable in your preferred profile file(/etc/profile, $HOME/.profile or /etc/environment):

    JAVA_HOME=/usr/lib/jvm/java-6-sun

    Refer to the first step of previous post in my Grails series if you need more help.

    1. Installing Groovy in Ubuntu 8.04 Using apt-get/aptitude

      To install Groovy and its dependency packages, run the following command in a command shell:

      # sudo aptitude install groovy

      You can also install Groovy from Synaptic Package Manager, simply search for package name called “groovy” in it. But have a look at the version number!

      Synaptic Package Manager shows an old version of Groovy package in Ubuntu 8.04 package repository

      See what I mean? The latest stable version of Groovy is 1.5.6 though I would recommend using the 1.6 beta 1.

    2. Installing Groovy in Ubuntu 8.04 Using GDebi

      If you don’t mind picking up a deb file from a third-party source, Groovy download page has Debian/Ubuntu packages for both 1.5.6 stable version and 1.6 beta 1 version.

      Groovy latest stable version for Debian/Ubuntu family of GNU/Linux distributions available as a deb package.

      When you download the Ubuntu deb binary from this page Ubuntu will automatically open it using GDebi and install it for you.

      Download the Groovy deb package from its download page and install it with GDebi application.

    3. Installing Groovy in Ubuntu 8.04 Using dpkg

      You can also save the deb file on your computer and install it from the command shell using the dpkg tool:

      # sudo dpkg -i <name-of-the-downloaded-deb-file>
    1. Installing Grails in Ubuntu 8.04 Using apt-get/aptitude

      Unfortunately there is no Grails package in Ubuntu official repositories yet. You can try any unofficial repositories for Grails available on the Internet but only if you trust them. An old repository meant for installing Grails 1.0 RC2 on Ubuntu Gutsy was posted on Ubuntu Forums by prach. Have a look at it just as an example, I don’t recommend actually using it. I don’t know of a similar repository for more recent versions of Grails. So better option will be to install the latest deb package of Grails using GDebi or dpkg tools; see the next step.

    2. Installing Grails in Ubuntu 8.04 Using GDebi

      You can follow the above procedure(Step 2(b)) used for Groovy to install Grails too, by downloading its deb package from Grails’s download page.

      Download the Groovy deb package from its download page and install it with GDebi application.

      Then choose to open the package with GDebi installer.

      Download the Grails deb package from its download page and install it with GDebi application.

    3. Installing Grails in Ubuntu 8.04 Using dpkg

      You can also save the deb file on your computer and install it from the command shell using the dpkg tool:

      # sudo dpkg -i <name-of-the-downloaded-deb-file>
  2. You can now go to the post where I show how to create a basic “Hello, World” Grails application to test your Grails configuration. (You can ignore the first step of that post.)

Summary:
To summarize, you can install Sun JDK, Groovy and Grails packages in Debian/Ubuntu family of distributions using simple commands, like this:

# sudo aptitude install sun-java6-jdk
# sudo echo ‘JAVA_HOME=/usr/lib/jvm/java-6-sun’ >> /etc/profile
# wget http://dist.codehaus.org/groovy/distributions/installers/deb/groovy-1.6-beta-1.deb
# sudo dpkg -i groovy-1.6-beta-1.deb
# wget http://ant-deb-task.googlecode.com/files/grails_1.0.3-1_all.deb
# sudo dpkg -i grails_1.0.3-1_all.deb

You can use similar commands/tools for other GNU/Linux distributions, like yum in Fedora, yast in openSUSE, emerge in Gentoo, etc. All the above download links point to the latest versions at the time of this writing, so remember to change them appropriately when updated versions are released.

Go to Top