Every Flavour Beans

“The time has come…to talk of many [technologies].” –Lewis Carroll(’The Walrus and the Carpenter’)
Development Tools. Web Frameworks. GNU/Linux. Nokia N800. Video Encoding.

August 4, 2008

Struts 2 Plugin for NetBeans IDE - nbstruts2support

Filed under: Java, Netbeans, Struts 2 — tabrez @ 10:09 pm

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.


If you want to receive future posts by email, enter your email address here:

Related Posts:

  • “Hello, World” Web Application using Struts 2 in IntelliJ IDEA 8.0 M1
  • “Hello, World” Web Application using Struts 2 in NetBeans IDE 6.1
  • Setting Up Rails Development Environment using Aptana Studio
  • Wordpress Upgrading Experience With Automatic Upgrade Plugin
  • Wordpress Plugin and Theme Cheatsheets
  • Develop Ruby Applications Using Eclipse IDE
  • Setting Up Rails Development Environment on Windows Vista/XP

  • Readers who viewed this page, also viewed:


    July 30, 2008

    “Hello, World” Web Application using Struts 2 in NetBeans IDE 6.1

    Filed under: Java, Netbeans, Struts 2 — tabrez @ 11:52 pm

    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:
      1. <?xml version="1.0" encoding="UTF-8"?>
      2. <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      3.     <filter>
      4.         <filter-name>Struts 2 filter</filter-name>
      5.         <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
      6.     </filter>
      7.     <filter-mapping>
      8.         <filter-name>Struts 2 filter</filter-name>
      9.         <url-pattern>/*</url-pattern>
      10.     </filter-mapping>
      11.     <session-config>
      12.         <session-timeout>
      13.             30
      14.         </session-timeout>
      15.     </session-config>
      16. </web-app>

      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:
      1. package hello;
      2. import com.opensymphony.xwork2.ActionSupport;
      3.  
      4. public class HelloStruts2World extends ActionSupport {
      5.     private String userName;
      6.     public String getUserName() {
      7.         return userName;
      8.     }
      9.     public void setUserName(String userName) {
      10.         this.userName = userName;
      11.     }
      12.  
      13.     private String message;
      14.     public String getMessage() {
      15.         return message;
      16.     }
      17.  
      18.     @Override
      19.     public String execute() {
      20.         message = "Hello, " + userName + ".";
      21.         return SUCCESS;
      22.     }
      23. }

    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:
      1. <!DOCTYPE struts PUBLIC
      2.     "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
      3.     "http://struts.apache.org/dtds/struts-2.0.dtd">
      4.  
      5. <struts>
      6.     <package name="/" extends="struts-default">
      7.         <action name="HelloStruts2World" class="hello.HelloStruts2World">
      8.             <result name="success">/index.jsp</result>           
      9.         </action>
      10.     </package>
      11. </struts>

      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:
      1. <%@page contentType="text/html" pageEncoding="UTF-8"%>
      2. <%@taglib prefix="s" uri="/struts-tags" %>
      3. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
      4.    "http://www.w3.org/TR/html4/loose.dtd">
      5.  
      6.     <head>
      7.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      8.         <title>Hello Struts 2 World Result Page</title>
      9.     </head>
      10.     <body>
      11.         <h2>Hello World!</h2>       
      12.         Struts 2 Message: <s:property value="message" default="Guest." />       
      13.        
      14.         <s:form method="GET" action="hello/HelloStruts2World.action">
      15.             Enter your name:<s:textfield name="userName" />
      16.             <s:submit value="Submit" />
      17.         </s:form>               
      18.     </body>
      19. </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.


    If you want to receive future posts by email, enter your email address here:

    Related Posts:

  • Struts 2 Plugin for NetBeans IDE - nbstruts2support
  • “Hello, World” Web Application using Struts 2 in IntelliJ IDEA 8.0 M1
  • “Hello, World” Web Application in Ruby on Rails using Aptana Studio
  • Setting Up Rails Development Environment on Windows Vista/XP
  • Creating “Hello World” Web Application Using the Grails Framework
  • Setting Up Development Environment For Grails on Windows Vista/XP
  • Setting Up Rails Development Environment using Aptana Studio

  • Readers who viewed this page, also viewed:



    Copyright (c) 2006, 2007 Tabrez Iqbal.
    Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. Verbatim copying and distribution of this entire article is permitted in any medium without royalty provided this notice is preserved. A copy of the license is included in the section entitled "GNU Free Documentation License".


    Powered by WordPress
    This website is hosted by Dreamhost