JBoss.org Community Documentation

Getting Started with JBoss Developer Studio

Version: 1.0.0.GA


1. Getting Started with JBoss Developer Studio
1.1. What is JBDS?
1.2. Configuring Your Java Environment
1.2.1. Installing and Configuring 32-bit Sun JDK 5.0 on Linux
1.2.2. Installing and Configuring 32-bit Sun JDK 5.0 on Microsoft Windows
1.3. JBoss Developer Studio Installation
1.3.1. Installing from the downloaded version
1.3.2. What is the difference between JBoss Developer Studio and JBoss Tools
1.4. Welcome to JBoss Developer Studio
1.5. Upgrading
1.6. Uninstalling
1.7. Support
1.8. FAQ
1.8.1. Installation Issues
1.8.2. Importing Projects
1.8.3. Troubleshooting, Problems, Configuration, Error Messages
1.9. Other relevant resources on the topic
2. Manage JBoss AS from JBoss Developer Studio
2.1. How to Manage the JBoss AS Bundled in JBDS
2.1.1. Starting JBoss server
2.1.2. Stopping JBoss Server
2.1.3. Server Container Preferences
2.2. How to Use Your Own JBoss AS Instance with JBDS
2.2.1. JBoss AS Installation
2.2.2. Adding and configuring JBoss server
3. Write Your First Seam Web Application
3.1. Create a Seam Project
3.2. Build and Deploy the Seam Application
3.3. Add a Web Page and an Action
3.4. Input Validation
3.5. Add a new UI Component
3.6. Add Security to the Application
3.7. Other relevant resources on the topic
4. Developing a simple JSP web application
4.1. Setting Up the Project
4.2. Creating JSP Page
4.2.1. Editing a JSP Page
4.2.2. web.xml file
4.2.3. Deploying the project
4.2.4. JSP Page Preview
4.2.5. Launch JSP Project
5. RAD development of a simple JSF application
5.1. Setting up the project
5.2. Creating JSP Pages
5.3. Creating Transition between two views
5.4. Creating Resource File
5.5. Creating Java Bean
5.6. Editing faces-config.xml File
5.7. Editing the JSP View Files
5.7.1. Editing inputnumber.jsp page
5.7.2. Editing success.jsp page
5.8. Creating index.jsp page
5.9. Running the Application
6. Further Reading

You must have a working installation of JDK 5 before you install JBoss Developer Studio. Currently it will only fully work with a 32-bit JVM, not a 64-bit JVM. On a 64-bit JVM the visual editor fails to launch. Thus in this guide we will show you how to install a 32-bit Sun JDK 5.0 on a Linux Platform and Microsoft Windows Platform.

To install 32-bit Sun JDK 5.0 on Linux and configure it, you should follow the next steps:

  • Download the Sun JDK 5.0 (Java 2 Development Kit) from Sun's website. Choose "JDK 5.0 Update <x>" (where "x" is the latest update number) for download and then select "RPM in self-extracting" file for Linux. Read the instructions on Sun's website for installing the JDK.

  • If you don't want to use SysV service scripts you can install the "self-extracting file" for Linux instead of choosing the "RPM in self-extracting" file. In that case you can skip the next step mentioned here. But it is recommended to use the SysV service scripts for production servers.

  • Download and install the appropriate -compat RPM from JPackage here. Please ensure you choose a matching version of the -compat package to the JDK you've installed.

  • Create an environment variable that points to the JDK installation directory and call it JAVA_HOME. Add $JAVA_HOME/bin to the system path to be able to run java from the command line. You can do this by adding the following lines to the .bashrc file in your home directory.

    #In this example /usr/java/jdk1.5.0_11 is the JDK installation directory.
    export JAVA_HOME=/usr/java/jdk1.5.0_11
    export PATH=$PATH:$JAVA_HOME/bin

Note:

When you add $JAVA_HOME/bin to $PATH, you should add it before the old $PATH not after it. This way, the machine will pick up the new JVM first. You only need to run "alternative" as a safe guard for the right JVM.

Set this variable for your account doing the installation and also for the user account that will run the server.

  • If you have more than one version of JVM installed on your machine, make sure you are using the JDK 1.5 installation as the default java and javac. You can do this using the alternatives system. The alternatives system allows different versions of Java from different sources to co-exist on your system.

[root@vsr ~]$ /usr/sbin/alternatives --config java
There are 2 programs that provide 'java'.
Selection    Command
-----------------------------------------------
   1           /usr/lib/jvm/jre-1.4.2-gcj/bin/java
*+ 2           /usr/lib/jvm/jre-1.5.0-sun/bin/java
Enter to keep the current selection[+], or type selection number:

Make sure the Sun version [jre-1.5.0-sun in this case] is selected (marked with a '+' in the output), or select it by entering its number as prompted.

[root@vsr ~]$ /usr/sbin/alternatives --config javac
There is 1 program that provides 'javac'.
	Selection   Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/java-1.5.0-sun/bin/javac
Enter to keep the current selection[+], or type selection number:

[root@vsr ~]$ /usr/sbin/alternatives --config java_sdk_1.5.0
There is 1 program that provide 'java_sdk_1.5.0'.
	Selection   Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/java-1.5.0-sun
Enter to keep the current selection[+], or type selection number:

You should verify that java, javac and java_sdk_1.5.0 all point to the same manufacturer and version.

[root@vsr ~]$ java -version
java version "1.5.0_11"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)
Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)

To install and configure 32-bit Sun JDK 5.0 on Microsoft Windows, follow these steps:

  • Download the Sun JDK 5.0 (Java 2 Development Kit) from Sun's website. Choose "JDK 5.0 Update <x>" (where "x" is the latest update number) for download and then select your Windows Platform options to perform the installation.

  • Create an environment variable called JAVA_HOME that points to the JDK installation directory, for example:

    C:\Program Files\Java\jdk1.5.0_11\

In order to run java from the command line, add the jre\bin directory to your path, for example:

C:\Program Files\Java\jdk1.5.0_11\jre\bin

To do this, open the Control Panel from the Start Menu, switch to Classic View if necessary, open the System Control Panel applet (System), select the Advanced Tab, and click on the Environment Variables button.

Now, when 32-bit Sun JDK 5.0 has been successfully installed, we can pass on to the next step.

This chapter will provide you with detailed information on how to install JBoss Developer Studio and all the JBoss Tools modules.

This release of JBoss Tools is what went into our JBoss Developer Studio which provides an easy-to-install Eclipse based IDE fully configured and ready to run with the bundled JBoss Enterprise Application Platform.

In short JBoss Tools are just a set of Eclipse plugins and JBoss Developer Studio adds:

For additional information see JBoss.com

Here, let's consider the installation of the JBoss Tools modules.

JBoss Tools is an umbrella project for the JBoss developed plugins that will make it into JBoss Developer Studio. The JBoss Tools modules are:

To install the JBoss Tools plugins for Eclipse, you need the following:

The quickest way to get a WTP version is to download "Eclipse IDE for Java EE Developers" via www.eclipse.org.

Note:

Remember to choose the download that matches your OS and use Java 5 when you run it.

You can also find the latest development release of JBossTools from JBossTools Stable Update Site

  • Finally, install the build

Unzip the file(s) directly into your Eclipse plugins/features directory and it will be readily available. It might be necessary to start Eclipse with eclipse -clean to make sure it starts clean and rereads the new list of plugins.

If you need to install any standalone plug-in from JBoss Tools visit a JBoss Tools Wiki page to read about dependencies between standalone plug-ins.

If you have comments or questions, you can discuss them at our JBoss Developer Studio Forum.

When writing to the forum for questions, please include the following information:

  1. JBoss Developer Studio version

  2. Exact error message

  3. Steps to reproduce the issue

For easy reference to JBoss Developer Studio related questions, our FAQ provides answers to the most "popular" questions. The sections of questions are organized by type.

In this chapter we'll focus more on how to operate the JBoss AS from JBoss Developer Studio.

JBoss Developer Studio ships with JBoss EAP v.4.2 bundled. When you followed the default installation of JBoss Developer Studio, you should already have a JBoss 4.2 server installed and defined. To run JBoss AS 4.2 you need JDK 1.5, JDK 6 is not formally supported yet, although you may be able to start the server with it.

This section covers the basics of working with the JBoss server supported directly by JBDS via bundled AS plug-in. To read more about AS plug-in, read Server Manager guide.

Although JBoss Developer Studio works closely with JBoss EAP 4.2 we do not ultimately tie you to any particular server for deployment. There are some servers that Studio supports directly (via the bundled Eclipse WTP plug-ins). In this section we discuss how to manage self-installed JBoss AS. Suppose you want to deploy the application to JBoss 4.2.1 server. First of all you need to install it.

It does not matter where on your system you install JBoss server.

Note:

The installation of JBoss server into a directory that has a name containing spaces provokes problems in some situations with Sun-based VMs. Try to avoid using installation folders that have spaces in their names.

There is no requirement for root access to run JBoss Server on UNIX/Linux systems because none of the default ports are within the 0-1023 privileged port range.

  • After you have the binary archive you want to install, use the JDK jar tool (or any other ZIP extraction tool) to extract the jboss-4.2.1.zip archive contents into a location of your choice. The jboss-4.2.1.tgz archive is a gzipped tar file that requires a gnutar compatible tar which can handle the long pathnames in the archive. The extraction process will create a jboss-4.2.1 directory.

Now we should add just installed server into server manager in JBoss Developer Studio.


  • Click Add button to add a new jboss runtime.

  • Select JBoss, a division of Red Hat > JBoss v4.2 and press Next.


  • In the next step make JBoss Developer Studio to know where you have installed the server and define JRE.


Note:

When adding a new server you will need to specify what JRE to use. It is important to set this value to a full JDK, not JRE. Again, you need a full JDK to run Web applications, JRE will not be enough.

  • In the following window leave all settings default or give your name to a new jboss server and press Finish.


A new runtime will now appear in the Preferences > Server > Installed Runtimes dialog.


  • Click OK. Then select a new added runtime in Server runtime drop down list and click Next button twice.


  • In the next dialog verify a JBoss runtime information and if something is unfair go back and correct it.


  • In the last wizard's dialog modify the projects that are configured on the server and click Finish.


A new JBoss server should now appear in JBoss Server View.


Now, we are ready to create the first web application.

The JBoss Developer Studio provides sophisticated tools for enterprise applications. With the JBoss Developer Studio, you can get started very quickly with a web prototype, and then scale up your application to include enterprise features (e.g., business processes, web services, etc.) using the same developer tools. It is a "scalable" RAD (Rapid Application Development) tool.

A core element that makes the JBoss Developer Studio "scalable" is the JBoss Seam framework.

The main purpose of this chapter is to tell you about build a simple Seam web application in minutes with the JBoss Developer Studio.

This section helps you to create a simple Seam project.

To create a new web application in Seam, you should create a Seam web project. This section provides all the necessary steps to organize a new project with appropriate tooling and adjust the settings that match your needs. In order to find out more information, see Seam Dev Tools Reference guide

First, select New > Project ... > Seam > Seam Web Project . You will be prompted to enter a name and a location directory for your new project. The wizard has an option for selecting the actual Server (and not just WTP runtime) that will be used for the project. This allow the wizard to correctly identify where the needed datasource and driver libraries need to go.


Next, you will be asked to select the "features" you want to use in your project. This allows JBoss Developer Studio to setup the appropriate tooling for your project. Since JBoss Seam integrates all popular Java EE frameworks, you can select any combination of technologies from the list. Here, for this project, we will select Dynamic Web Module, Java, JavaServer Faces (JSF), and Seam Facet for a typical database-driven web application.


In this screen you can also bring up server runtimes panel by clicking Show Runtimes in the bottom right corner. This panel shows available server runtimes. Then this button will be changed into Hide Runtimes one.

Click Next to proceed further.


A dynamic web application contains both web pages and Java code. The wizard will ask you where you want to put those files. You can just leave the default values or choose another folder.


On the next form, you will be able to select where those library JARs come from. The easiest is just to select the JARs provided by the JBoss AS runtime associated with this project. That is why it is important to chose the right JBoss AS 4.2 runtime in the project setup window.


We will also use a default Hibernate Dialect - org.hibernate.dialect.HSQLDialect and deploy as a war archive.

The project setup wizard also asks you to configure how Seam generates code for the project. The Seam Home Folder should point to a valid Seam distribution. By default, it is set to the Seam distribution bundled in your JBoss Developer Studio tool. If you need another one choose setting up the appropriate check box:


If in this list there is no Seam runtime you want to use add it through Window > Preferences > JBoss Tools > Web > Seam or just click Add button near the Seam Runtime list:


For the deployment format, choose WAR deployment if you want to use POJOs for UI event handling and business logic; choose EAR deployment if you want to EJB3 beans for added features. In most web applications, the WAR deployment option would suffice. You should also enter Java packages for the entity beans (for database mapping) and session beans (for action handlers). All generated code will be placed in those packages.

Click on Finish to generate a project. The generated project contains all the necessary library JARs, XML configuration files, the ANT build script, as well as simple XHTML web pages and Java classes for the skeleton web application. The project will be shown in Project Explorer as well as in Seam Components view. If Seam Components view is not open select Window > Show View > Seam Components .


You can hide unused Seam components from this view.

  • Click the button Menu on the top of the view (down-pointing arrow)

  • Choose Customize View..

  • In the dialog Available Customization check the filter you want to apply under the Filters tab


Here, we are going to add a new page and related UI action to the project.

To do this use the New > Other ... > Seam > Seam Form wizard. You are prompted to enter the name of the project and seam component name, all the others fields will be filled by the wizard.


The wizard generate a web page with a single text input field and an action button. Notice that the generated page uses layout/template.xhtml as a template. The template page provides the page header, footer, side menu, and CSS styles (see the template.xhtml for more details). The simpleAction.xhtml is assembled into the template when the simpleAction.seam URL is loaded.



<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
                "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

  <ui:composition>  xmlns:s="http://jboss.com/products/seam/taglib"
                              xmlns:ui="http://java.sun.com/jsf/facelets"
                              xmlns:f="http://java.sun.com/jsf/core"
                              xmlns:h="http://java.sun.com/jsf/html"
                              template="layout/template.xhtml">

<ui:define name="body">

    <h:messages globalOnly="true" styleClass="message"/>

    <h:form id="simpleActionForm">
        <rich:panel>
            <f:facet name="header">simpleAction</f:facet>
                    <s:decorate id="valueDecoration" template="layout/edit.xhtml">
                        <ui:define name="label">Value</ui:define>
                        <h:inputText id="value" required="true"
                            value="#{simpleAction.value}"/>
                    </s:decorate>
                    <div style="clear:both"/>
         </rich:panel>
         
         <div class="actionButtons">
             <h:commandButton id="simpleAction" value="simpleAction"
                             action="#{simpleAction.simpleAction}"/>
        </div>
    </h:form>
</ui:define>

</ui:composition>

The #{simpleAction.value} notation on the web page maps to the "value" property in the backend component named "simpleAction", and the #{simpleAction.simpleAction} notation indicates that the simpleAction() method is called when the button is clicked on. Here is the "simpleAction" named backend Seam component generated by the wizard.

package org.domain.MySeamProj.session;

    
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.log.Log;
import org.jboss.seam.core.FacesMessages;
import org.hibernate.validator.Length;
    
@Name("simpleAction")
public class SimpleAction {
    @Logger private Log log;
    @In
    FacesMessages facesMessages;
    private String value;
    //seam-gen method
    public void simpleAction()
    {
        //implement your business logic here
        log.info("simpleAction.simpleAction() 
              action called with: #{simpleAction.value}");
        facesMessages.add("simpleAction #{simpleAction.value}");
    }
    //add additional action methods
    @Length(max=10)
    public String getValue()
    {
        return value;
    }
    public void setValue(String value)
    {
        this.value = value;
    }
}

Load the Simplepage.seam in the web browser. Type something in the text field and click on the "simpleAction" button. A JSF message containing the input string is created by the simpleAction.simpleAction() method. The message is displayed on the page via the <h:message> tag.

Note:

We highly recommend developing in Seam. This chapter is for users who for some reason cannot use Seam.

In this chapter you'll find out how to create a simple JSP application using the JBoss Developer Studio. The application will show a classic "Hello World!" on the page.

We'll assume that you have already launched JBoss Developer Studio and also that the Web Development perspective is the current perspective. If not, make it active by selecting Window > Open Perspective > Web Development from the menu bar or by selecting Window > Open Perspective > Other... from the menu bar and then selecting Web Development from the Select Perspective dialog box.

This section covers all the points how to create, edit and then preview JSP page.

In our simple application we need to create only one JSP page which displays a "Hello World!" message.

In the next window you can choose a template for your jsp page and see its preview.


Our hello.jsp page will now appear in Project Explorer.

While creating any web project you could experience a pain writing ant scripts and managing the packaging even if a developer is writing the most trivial web applications. With JBoss Developer Studio you are saved from such a pain. All you need is to start JBoss server and launch your application in your favorite browser.

You can also create a war archive with JBDS's Archive Tools and export it to any web server.

Note:

We highly recommend developing in Seam. This chapter is for users who for some reason cannot use Seam.

In this chapter you will see how to create a simple JSF application being based on "RAD" philosophy. We will create the familiar Guess Number application. The scenario is the following. You are asked to guess a number between 0 and 100. If the guess is correct, a success page is displayed with a link to play again. If the guess is incorrect, a message is printed notifying that a smaller or a larger number should be entered and the game continues.

We'll show you how to create such an application from scratch, along the way demonstrating powerful features of JBoss Developer Studio such as project templating, Visual Page Editor, code completion and others. You will design the JSF application and then run the application from inside JBoss Developer Studio using the bundled JBoss server.