Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Red Hat JBoss Developer Studio

7.1

Getting Started Guide

Information for first time users

Red Hat Documentation Team

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Information for first time users

Red Hat Do cumentatio n Team

Legal Notice

Copyright © 2013 Red Hat, Inc.

This document is licensed by Red Hat under the

Creative Commons Attribution-ShareAlike 3.0 Unported

License

. If you distribute this document, or a modified version of it, you must provide attribution to Red

Hat, Inc. and provide a link to the original. If the document is modified, all Red Hat trademarks must be removed.

Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section

4d of CC-BY-SA to the fullest extent permitted by applicable law.

Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the Infinity Logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.

Linux ® is the registered trademark of Linus Torvalds in the United States and other countries.

Java ® is a registered trademark of Oracle and/or its affiliates.

XFS ® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.

MySQL ® is a registered trademark of MySQL AB in the United States, the European Union and other countries.

Node.js ® is an official trademark of Joyent. Red Hat Software Collections is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.

The OpenStack ® Word Mark and OpenStack Logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.

All other trademarks are the property of their respective owners.

Abstract

This document details how to install JBoss Developer Studio and guides you through creating an application using some of JBoss Developer Studio's tools.

Table of Contents

1. Document Conventions

1.1. Typographic Conventions

1.2. Pull-quote Conventions

1.3. Notes and Warnings

2. Getting Help and Giving Feedback

1.1. About Red Hat JBoss Developer Studio

1.2. Use Cases of JBoss Developer Studio

2.1. About Getting Started

3.1. Installation Assumptions

3.2. Install JBoss Developer Studio

3.3. Select a Workspace Location

3.4. Set Usage Reporting

4.1. About the TicketMonster Application

4.2. Tutorial Outline

4.3. Tutorial Assumptions

5.1. Configure Maven

5.2. Set Up a Server Using Runtime Detection

5.3. Create a Java EE Web Project Using JBoss Central

5.4. Add an Entity Using Forge Tools

5.5. Add an Entity Using Hibernate Tools

5.6. Prepare Event Records to Populate the Database

5.7. Deploy the Application using JBoss Server Tools

5.8. Access and Query the Database

5.9. Add a RESTful Web Service

5.10. Add a User Interface Optimized for Mobile Devices

5.11. Test the Mobile User Interface Using BrowserSim

6.1. Uninstall JBoss Developer Studio

Table of Contents

20

21

23

26

28

32

34

37

39

44

49

52

11

11

14

15

18

18

19

7

7

10

4

5

3

3

5

1

2

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Preface

Preface

1. Document Conventions

This manual uses several conventions to highlight certain words and phrases and draw attention to specific pieces of information.

In PDF and paper editions, this manual uses typefaces drawn from the Liberation Fonts set. The

Liberation Fonts set is also used in HTML editions if the set is installed on your system. If not, alternative but equivalent typefaces are displayed. Note: Red Hat Enterprise Linux 5 and later include the Liberation

Fonts set by default.

1.1. Typographic Conventions

Four typographic conventions are used to call attention to specific words and phrases. These conventions, and the circumstances they apply to, are as follows.

Mono-spaced Bold

Used to highlight system input, including shell commands, file names and paths. Also used to highlight keys and key combinations. For example:

To see the contents of the file my_next_bestselling_novel in your current working directory, enter the cat my_next_bestselling_novel command at the shell prompt and press Enter to execute the command.

The above includes a file name, a shell command and a key, all presented in mono-spaced bold and all distinguishable thanks to context.

Key combinations can be distinguished from an individual key by the plus sign that connects each part of a key combination. For example:

Press Enter to execute the command.

Press Ctrl+Alt+F2 to switch to a virtual terminal.

The first example highlights a particular key to press. The second example highlights a key combination: a set of three keys pressed simultaneously.

If source code is discussed, class names, methods, functions, variable names and returned values mentioned within a paragraph will be presented as above, in mono-spaced bold. For example:

File-related classes include filesystem for file systems, file for files, and dir for directories. Each class has its own associated set of permissions.

Proportional Bold

This denotes words or phrases encountered on a system, including application names; dialog-box text; labeled buttons; check-box and radio-button labels; menu titles and submenu titles. For example:

Choose SystemPreferencesMouse from the main menu bar to launch Mouse

Preferences. In the Buttons tab, select the Left-handed mouse check box and click

Close to switch the primary mouse button from the left to the right (making the mouse suitable for use in the left hand).

To insert a special character into a gedit file, choose ApplicationsAccessories

3

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Character Map from the main menu bar. Next, choose SearchFind… from the

Character Map menu bar, type the name of the character in the Search field and click

Next. The character you sought will be highlighted in the Character T able. Double-click this highlighted character to place it in the Text to copy field and then click the Copy button. Now switch back to your document and choose EditPaste from the gedit menu bar.

The above text includes application names; system-wide menu names and items; application-specific menu names; and buttons and text found within a GUI interface, all presented in proportional bold and all distinguishable by context.

Mono-spaced Bold Italic or Proportional Bold Italic

Whether mono-spaced bold or proportional bold, the addition of italics indicates replaceable or variable text. Italics denotes text you do not input literally or displayed text that changes depending on circumstance. For example:

To connect to a remote machine using ssh, type ssh username@domain.name at a shell prompt. If the remote machine is example.com and your username on that machine is john, type ssh [email protected].

The mount -o remount file-system command remounts the named file system. For example, to remount the /home file system, the command is mount -o remount /home.

To see the version of a currently installed package, use the rpm -q package command. It will return a result as follows: package-version-release.

Note the words in bold italics above: username, domain.name, file-system, package, version and release.

Each word is a placeholder, either for text you enter when issuing a command or for text displayed by the system.

Aside from standard usage for presenting the title of a work, italics denotes the first use of a new and important term. For example:

Publican is a DocBook publishing system.

1.2. Pull-quote Conventions

Terminal output and source code listings are set off visually from the surrounding text.

Output sent to a terminal is set in mono-spaced roman and presented thus: books Desktop documentation drafts mss photos stuff svn books_tests Desktop1 downloads images notes scripts svgs

Source-code listings are also set in mono-spaced roman but add syntax highlighting as follows:

4

Preface package org.

jboss .

book .

jca .

ex1 ; import javax.naming.InitialContext; public class ExClient

{ public static void main (String args[]) throws Exception

{

InitialContext iniCtx = new InitialContext();

Object ref = iniCtx.

lookup ( "EchoBean" );

EchoHome home = (EchoHome) ref;

Echo echo = home.

create ();

System.

out .

println ( "Created Echo" );

System.

out .

println ( "Echo.echo('Hello') = " + echo.

echo ( "Hello" ));

}

}

1.3. Notes and Warnings

Finally, we use three visual styles to draw attention to information that might otherwise be overlooked.

Note

Notes are tips, shortcuts or alternative approaches to the task at hand. Ignoring a note should have no negative consequences, but you might miss out on a trick that makes your life easier.

Important

Important boxes detail things that are easily missed: configuration changes that only apply to the current session, or services that need restarting before an update will apply. Ignoring a box labeled “Important” will not cause data loss but may cause irritation and frustration.

Warning

Warnings should not be ignored. Ignoring warnings will most likely cause data loss.

2. Getting Help and Giving Feedback

Do You Need Help?

If you experience difficulty with a procedure described in this documentation, visit the Red Hat Customer

Portal at http://access.redhat.com

. Through the customer portal, you can: search or browse through a knowledgebase of technical support articles about Red Hat products.

submit a support case to Red Hat Global Support Services (GSS).

access other product documentation.

5

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Red Hat also hosts a large number of electronic mailing lists for discussion of Red Hat software and technology. You can find a list of publicly available mailing lists at https://www.redhat.com/mailman/listinfo .

Click on the name of any mailing list to subscribe to that list or to access the list archives.

Give us Feedback

If you find a typographical error or have a suggestion for improving this documentation, we would love to hear from you. Submit a report in JIRA against the project Documentation for JBoss Tools and

Developer Studio (TOOLSDOC). The following link will take you to a pre-filled bug report for this product: https://issues.jboss.org

.

Fill out the following template in JIRA's Description field. Be as specific as possible when describing the issue; this will help ensure that we can fix it quickly.

Document URL:

Section Number and Name:

Describe the issue:

Suggestions for improvement:

Additional information:

Be sure to give us your name so that you can receive full credit for reporting the issue.

6

Chapter 1. Introduction to Red Hat JBoss Developer Studio

Chapter 1. Introduction to Red Hat JBoss Developer Studio

1.1. About Red Hat JBoss Developer Studio

Red Hat JBoss Developer Studio is a set of Eclipse-based development tools. It contains plug-ins that integrate with Eclipse to extend the existing functionality of the integrated development environment

(IDE).

JBoss Developer Studio is designed to increase your productivity when developing applications. You can focus on building, testing and deploying your applications because JBoss application development tools are integrated in one IDE. Furthermore, JBoss Developer Studio can assist your application development with its unique features in the following ways:

Develop new applications using the wizards and project examples of JBoss Central

Add powerful functionality to applications with minimal effort using Forge Tools

Build web interfaces with ease using the visual editing and drag-and-drop utilities of Visual Web

Tools and Mobile Web Tools

Experience browsers automatically refreshing in response to modified application resources with

LiveReload Tools

Incorporate JSF, Seam, JAX-RS, Hibernate, CDI and other popular APIs into applications with simplicity using the tool-driven interface

Preview and test mobile web applications on a variety of simulation mobile devices using BrowserSim

Create, build and test Cordova-based hybrid mobile applications for iOS and Android platforms using

Hybrid Mobile Tools and CordovaSim

Deploy applications to JBoss runtime servers and the cloud using JBoss Server Tools and

OpenShift Tools

JBoss Developer Studio comes built around Eclipse and packaged with all of the necessary dependencies and third-party plug-ins for simplified installing. For developers already running Eclipse,

JBoss Developer Studio can also be installed through Eclipse Marketplace. For distinction, this latter

JBoss Developer Studio installation is called JBoss Developer Studio BYOE (Bring Your Own Eclipse).

Report a bug

1.2. Use Cases of JBoss Developer Studio

JBoss Developer Studio assists JEE developers by integrating JBoss technology and APIs in a single development environment. Here are a few ways that JBoss Developer Studio makes the work of a developer easier:

Web applications

JBoss Central provides wizards that generate skeleton and sample projects, enabling you to focus on developing the functionality of your applications. The wizards create web applications based on different APIs and technologies, showing the usage and advantages of each.

JBoss Developer Studio also offers project file templates in a range of popular programming languages, including HTML, XHTML, and JSF.

Palettes in JBoss Developer Studio give access to the core elements of the JSF, Richfaces and

Seam APIs, for use in developing the user interfaces of your applications. Elements of these

APIs can be dragged and dropped directly into your project so that you can create richer user interfaces quickly. Visual Web Tools offers graphical and source viewing of files and defaults to dedicated editors for different file types. JBoss Developer Studio supports the Java EE

7

8

Red Hat JBoss Developer Studio 7.1 Getting Started Guide specification and provides tools for JAX-RS, Hibernate, and CDI APIs so you can develop the server-side components of your applications effortlessly.

LiveReload Tools automatically refreshes browsers of local or deployed applications as you modify project resources to save you from needing to manually refresh. You can even experience automatic refreshing when viewing applications in browsers on external and mobile devices, with application web addresses easy to navigate to with QR codes.

Web applications optimized for mobile devices

Mobile Web Tools provides support for HTML5 and jQuery Mobile to enable you to create web applications optimized across desktop and mobile clients. The HTML5 Project wizard in JBoss

Central generates a sample application using HTML5 and jQuery Mobile technologies and, together with HTML5 and jQuery Mobile project file templates, helps you to get up and running with these APIs and technologies quickly. HTML5 and jQuery Mobile widgets can be dragged from the jQuery Mobile palette into your project files and, in conjunction with the widget wizards, enable you to effortlessly develop customized user interfaces for your mobile web applications.

BrowserSim allows you to view your web applications on a variety of simulated mobile devices so that you can ensure they will be correctly formatted. LiveReload also extends to BrowserSim allowing you to experience automatic browser refreshing as you develop your mobile web applications. The integration of Firebug Lite and Weinre capabilities with BrowserSim assists you to inspect the page source of web pages with familiar tools.

Hybrid mobile applications

Hybrid Mobile Tools provides support for developing and building Cordova-based hybrid mobile applications for iOS and Android platforms. The Hybrid Mobile application wizard assists you to quickly generate new projects, while the Cordova Configuration Editor and Cordova Plug-in

Discovery wizard help you to efficiently modify the capabilities of your projects. Hybrid Mobile

Tools provides actions that simplify your workflow, for example calling your system installed

Android and iOS SDKs from within the IDE to emulate or run your hybrid mobile applications.

With wizards to export workspace projects to Cordova-enabled native projects or ready-to-sign applications, you can quickly be ready to share your hybrid mobile projects and applications.

CordovaSim enables you to view and test your hybrid mobile applications on Android and iOS simulated mobile devices so that you can ensure they look and work as expected. You can interact with your mobile applications through BrowserSim and use the device input panel to provide sample data to your applications for device functions like cameras and accelerometers.

An advantage of CordovaSim is that it does not require native SDKs to be installed on your system, unlike native SDK emulators. Additionally, by teaming the device control panel with

BrowserSim, you get all of the great functionality of BrowserSim, such as skins and LiveReload, while simulating your hybrid mobile applications.

Applications for cloud deployment

OpenShift Tools deploys your applications directly to the cloud on the Red Hat OpenShift platform. You can create and manage your OpenShift account and manage the deployment of applications in your OpenShift domains from within the IDE. In addition to using the OpenShift

Application wizard to create new applications for deployment to OpenShift, OpenShift Tools can import applications already deployed on OpenShift so that you can further develop them and manage their deployment from the comfort of the IDE.

Report a bug

Chapter 1. Introduction to Red Hat JBoss Developer Studio

9

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Chapter 2. Getting Started with JBoss Developer Studio

2.1. About Getting Started

Getting Started is a step-by-step guide that introduces JBoss Developer Studio to new users. It aims to give you a taste of developing applications with JBoss Developer Studio.

The guide covers three topics: how to install and set up JBoss Developer Studio how to create a web application, TicketMonster, with JBoss Developer Studio how to uninstall JBoss Developer Studio

In guiding you through these topics, a number of assumptions are made about your system. The assumptions are associated with installing JBoss Developer Studio and working through the

TicketMonster tutorial and they are detailed in the appropriate sections of the guide.

Additionally, the information in the guide is minimal. It describes one method of installing

JBoss Developer Studio and one way of completing each step in the TicketMonster tutorial. In fact, there is more than one method to install JBoss Developer Studio and there may be several alternatives for each step in the TicketMonster tutorial. For more information about the alternative installation methods and alternative ways to complete tasks, see Red Hat JBoss Developer Studio 7.1 Installation Guide and

User Guide.

Report a bug

10

Chapter 3. Install JBoss Developer Studio

Chapter 3. Install JBoss Developer Studio

3.1. Installation Assumptions

The installation method described in this guide is for JBoss Developer Studio.

Note

If you want to install JBoss Developer Studio BYOE, follow the instructions in Red Hat

JBoss Developer Studio 7.1 Installation Guide and then continue to work through the

TicketMonster tutorial in this guide.

To ensure successful installation, a number of assumptions are made about your system:

Your system meets the system requirements for installing JBoss Developer Studio 7.1, as set out in

Red Hat JBoss Developer Studio 7.1 Installation Guide. The system requirements concern having a compatible operating system, sufficient computer memory and a compatible Java developer kit.

You are aware of the Visual Page Editor tool limitations on 64-bit OS X and Microsoft Windows operating systems and will use the workaround detailed in Red Hat JBoss Developer Studio 7.1

Installation Guide.

You are aware of the BrowserSim tool limitations on 64-bit Microsoft Windows operating systems and will use the workaround detailed in Red Hat JBoss Developer Studio 7.1 Installation Guide and User

Guide.

Report a bug

3.2. Install JBoss Developer Studio

A universal installer .jar file is provided for installing JBoss Developer Studio and it is available from the Red Hat Customer Portal. The procedure below guides you though obtaining the universal installer and the installation process.

Procedure 3.1. Install with the Universal Installer

1. Log into the Customer Portal at https://access.redhat.com

.

2. From the menu bar click Downloads.

3. Under Red Hat JBoss Middleware, click Download Software.

Figure 3.1. Download Red Hat JBoss Middleware Software on the Customer Portal

11

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

4. Under Software Downloads, select the following options:

From the Product list, select JBoss Developer Studio.

From the Version list, select 7.1.x.

5. From the table click Download for the Red Hat JBoss Developer Studio 7.1.x Stand

Alone Universal Binary download file. This downloads the universal installer .jar file.

6. On the command line, navigate to path/to/.jar and enter java -jar jbdevstudio-product-universal-version.jar

where version is substituted to match the name of the .jar file.

Note

Alternatively, to start the installer you may be able to double-click the .jar file.

7. When the Installer window opens, click Next.

8. After reading and agreeing to the terms of the End User License Agreement, click I accept the

term s of this license agreem ent and click Next.

9. In the Select the installation path field, type the path where you want

JBoss Developer Studio to be installed or click Browse to navigate to the location. When the

Select the installation path field shows the correct path, click Next. When you are prompted about the specified location being created or overwritten, review the message and, if satisfied, click OK or Yes as appropriate.

Figure 3.2. Installation Step 3: Select Target Folder

10. In the Select Java VM step, Default Java VM is automatically selected. Ensure that the

12

Chapter 3. Install JBoss Developer Studio disabled text field contains the path of the Java developer kit you want to use. This is based on the default Java developer kit of your system. To change the specified Java developer kit, click

Specific Java VM and type the path of the Java developer kit in the text field or use the

Browse button to locate the Java developer kit. When the text field shows the correct Java developer kit path, click Next.

Important

You must specify a Java developer kit with a 32-bit JRE to install a 32-bit version of

JBoss Developer Studio and a 64-bit JRE to install a 64-bit version of

JBoss Developer Studio. To change the bit version of the Java developer kit to be used for installing JBoss Developer Studio, complete the appropriate step for your operating system:

On OS X operating systems, from the Installation type list click the appropriate bit version.

On Linux distributions and Microsoft Windows operating systems, in the text field type the path to the appropriate bit version of the Java developer kit.

Figure 3.3. Installation Step 4 : Select Java VM

11. Automatic runtime detection for finding application servers is set up using an alternative method later in the TicketMonster tutorial. Click Next to skip over this step in the installation process.

12. Review the details in the Summary Information window and, if they are correct, click Next.

Installation commences.

13. When the Pack installation progress bar shows Finished, click Next. The installation process is now complete.

13

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Figure 3.4 . Installation Step 7: Installation Progress in Finished State

14. To create shortcuts for starting JBoss Developer Studio, select the Create shortcuts in

the Start-Menu and Create additional shortcut on the desktop check boxes and click Next.

15. To automatically start JBoss Developer Studio when the Installer window closes, select the

Run JBoss Developer Studio after installation check box. Click Done to close the

Installer window.

Important

Linux distributions have a maximum number of files that a process can have open at one time. If this maximum number of files is set too low, JBoss Developer Studio will not start. You must open the /etc/security/limits.conf file and ensure that the soft nofile and hard nofile variables have values of 9216 at a minimum. If the variables have smaller values, the values must be increased to 9216. If the variables are not specified, the following lines must be added to the file:

* soft nofile 9216

* hard nofile 9216

Report a bug

3.3. Select a Workspace Location

14

Chapter 3. Install JBoss Developer Studio

When the IDE starts, you are asked to choose the workspace folder for the session. The workspace is where your projects are stored.

Figure 3.5. Select a Workspace Window

To set the workspace location, follow these steps:

1. In the Workspace field, type the path for a new or existing workspace or use Browse to navigate to the workspace location.

2. If you do not want to be asked to choose a workspace folder each time the IDE starts, select the

Use this as the default and do not ask again check box.

3. Click OK.

The workspace location prompting behavior can be altered at any time by clicking

WindowPreferences. Expand GeneralStartup and Shutdown and select Workspaces.

Select or clear the Prompt for workspace on startup check box to alter the behavior as appropriate.

Report a bug

3.4. Set Usage Reporting

JBoss Developer Studio has usage reporting. At the first start of the IDE after installing, you are asked if you allow the collection of anonymous usage statistics by JBoss Developer Studio.

15

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Figure 3.6. Prompt for Anonymous Usage Statistics

The information collected enables Red Hat to understand how and where JBoss Developer Studio is being used. Specifically, information about operating systems and system display resolution assists in continually improving JBoss Developer Studio.

The following information is collected:

Version of JBoss Developer Studio

Installed components of JBoss Developer Studio

JBoss Central enabled

Origin of Eclipse product

Version of Eclipse

Operating system

Operating system version

Linux distribution and version, if appropriate

Screen colors

Screen resolution

Version of Java

Internet connection type

Location (continent, country, city) and language

User type (new or returning)

Number of times JBoss Developer Studio has been started

Date of first usage reported

Date of last usage reported

Date of current usage reported

If enabled, the usage reporting plug-in uses Google Analytics to track data as though you visited a page under https://devstudio.jboss.com/usage .

To agree to this anonymous information being collected, click Yes when prompted.

The usage reporting behavior can be changed at any time by clicking WindowPreferences. Expand

JBoss T ools and select Usage Reporting. Select or clear the Please allow Red Hat Inc.

to receive anonym ous usage statistics for this JBoss Developer Studio

installation check box to alter the behavior as appropriate.

Report a bug

16

Chapter 3. Install JBoss Developer Studio

17

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Chapter 4. Introduction to the TicketMonster Application

4.1. About the TicketMonster Application

TicketMonster is an example web application demonstrating ticket purchasing. The application provides an online environment in which users can purchase tickets for events and administrators can manage the data relating to events and ticket sales. You can see a running example of the TicketMonster application at https://ticketmonster-jdf.rhcloud.com/ .

The application consists of a user interface and web services. The user interface allows users to purchase tickets for listed events and it enables administrators to access and modify event and ticket information. The user interface is optimized for desktop and mobile clients. The web services enable access to information about members, events and venues stored in a database.

TicketMonster demonstrates the combining of Red Hat and JBoss technologies and frameworks to build, test and deploy applications. For example, the running instance of TicketMonster at https://ticketmonsterjdf.rhcloud.com/ is hosted in the cloud on the OpenShift platform.

Report a bug

4.2. Tutorial Outline

The diversity and complexity of the TicketMonster application makes it ideal for demonstrating some of the capabilities of JBoss Developer Studio. This tutorial sets the stage for building TicketMonster. It shows you how to develop a number of the TicketMonster application features using

JBoss Developer Studio:

Configure Maven for use with JBoss Central projects

Set up a server using JBoss Server Tools runtime detection

Create a Java EE web project to which the TicketMonster functionality is added using JBoss Central

Create Event and Venue entity classes for the database entities using Forge Tools and Hibernate

Tools

Prepare event records to populate the database at runtime

Deploy the application on a runtime server using JBoss Server Tools

Access and query the database holding the member, event and venue records

Add a RESTful web service so that the application can retrieve the information in the database

Add a user interface to the application that is optimized for mobile devices using Mobile Web Tools

Test the mobile user interface using BrowserSim

You must work through these tasks in the order they are presented because the earlier tasks are prerequisites for the later tutorial tasks.

Note

For information about building the complete TicketMonster application using

JBoss Developer Studio see http://www.jboss.org/jdf/examples/get-started/ on the

JBoss Developer Framework website.

Report a bug

18

Chapter 4. Introduction to the TicketMonster Application

4.3. Tutorial Assumptions

The TicketMonster application is built on a Maven-based Java EE Web project. To ensure successful completion of the tutorial, a number of assumptions are made about your system:

JBoss Developer Studio 7.1 is installed

JBoss Enterprise Application Platform 6.x is installed

JBoss Enterprise Application Platform 6.x Maven repository is installed but Maven is not necessarily configured to use it

Report a bug

19

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Chapter 5. Creating the TicketMonster Application

5.1. Configure Maven

The Java EE Web Project, on which the TicketMonster application is based, is constructed from a Maven archetype. Maven is distributed with JBoss Developer Studio so it is not necessary to install Maven but, to be able to use the Java EE Web Project wizard with JBoss Enterprise Application Server 6.x, Maven must be correctly configured. The procedure below demonstrates how to configure Maven for use with

JBoss Enterprise Application Server 6.x by editing the Maven configuration file from within

JBoss Developer Studio.

Procedure 5.1. Configure Maven

1. Click WindowPreferences, expand JBoss Tools and select JBoss Maven Integration.

20

Figure 5.1. JBoss Maven Integration Pane in the Preferences Window

2. Click Configure Maven Repositories.

3. Click Add Repository.

4. Click Recognize JBoss Maven Enterprise Repositories.

5. Navigate to path/to/jboss-eap-6.x.y-maven-repository and click OK. JBoss Maven

Tools recursively scans the path searching for the Maven repository.

6. Modify the information in the ID and Name fields as desired, ensure the Active by default check box is selected and click OK.

Chapter 5. Creating the TicketMonster Application

Figure 5.2. Add Maven Repository Window

7. Click Finish and at the prompt asking if you are sure you want to update the Maven configuration file click Yes. If the specified configuration file does not exist, JBoss Maven Tools creates it.

Note

Maven settings, such as the configuration file, are specified in Preferences under

MavenUser Settings. These settings can be customized.

8. Click Apply and click OK to close the Preferences window.

Report a bug

5.2. Set Up a Server Using Runtime Detection

Servers can be defined from within the Java EE Web Project wizard. But for the purposes of exploring

JBoss Developer Studio the procedure below defines the server first using JBoss Server Tools runtime detection.

Procedure 5.2. Define a Server Using Runtime Detection

1. Click WindowPreferences, expand JBoss Tools and select JBoss Runtime Detection.

21

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Figure 5.3. JBoss Runtime Detection Pane

2. Click Add.

3. Select the directory containing the JBoss Enterprise Application Platform 6.0 or

JBoss Enterprise Application Platform 6.1 installation and click OK. The directory is now scanned for application servers and JBoss Enterprise Application Platform 6.x found.

22

Figure 5.4 . JBoss Enterprise Application Platform 6.x Found by Runtime Detection

4. To create a server for JBoss Enterprise Application Platform 6.x, ensure the jboss-eap-6.x check box is selected and click OK.

5. Click Apply and click OK to close the Preferences window. The server is listed in the Servers view.

Chapter 5. Creating the TicketMonster Application

Figure 5.5. JBoss Enterprise Application Platform 6.x Server Listed in Servers View

6. The server is initially shown in stopped mode. To start the server, right-click jboss-eap-6.x and click Start. After a short pause, the view switches to the Console view and shows the startup output of the server.

Report a bug

5.3. Create a Java EE Web Project Using JBoss Central

The TicketMonster application is based on a Java EE web application. A wizard is provided for creating this type of project in JBoss Central and the procedure below guides you through using the wizard.

Procedure 5.3. Create a Web Application Using the Java EE Web Project Wizard

1. Click the JBoss Central tab.

2. In JBoss Central under Start from scratch, click Java EE Web Project to open the Java

EE Web Project wizard. If JBoss Central is not visible, click HelpJBoss Central.

Figure 5.6. Java EE Web Project in JBoss Central

3. From the Target Runtime list, select jboss-eap-6.x Runtime and click Next.

23

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

24

Figure 5.7. JBoss Enterprise Application Platform 6.x Selected as Target Runtime in

Java EE Web Project Wizard

4. In the Project name field, type ticket-monster.

5. In the Package field, type org.jboss.jdf.example.ticketmonster and click Finish to create the project.

Chapter 5. Creating the TicketMonster Application

Figure 5.8. Completed Project Name and Package Fields in Java EE Web Project

Wizard

6. During project creation, the wizard imports project dependencies. When the Java EE Web

Project wizard displays 'Java EE Web Project' Project is now ready, click Finish to close the wizard. A README.md file for the project automatically opens for viewing and the project is listed in the Project Explorer view.

25

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Figure 5.9. 'Project is now ready' Message in Java EE Web Project Wizard

Report a bug

5.4. Add an Entity Using Forge Tools

A new entity class can be added to the TicketMonster project using Forge Tools. In the procedure below an Event entity class is created to hold information about the events for which users can buy tickets.

This Event entity has id, name, description, major and picture fields.

Procedure 5.4 . Add an Entity Using Forge Tools

1. In the Project Explorer view, expand ticket-monsterJava

Resourcessrc/m ain/java.

2. Right-click org.jboss.jdf.example.ticketmonster.model and click Show InForge

Console.

26

Chapter 5. Creating the TicketMonster Application

Figure 5.10. Show In→Forge Console Menu Option

3. When asked Do you want to start the Forge runtime? click Yes. The Forge

Console view opens and Forge is started. The first command is automatically entered on the

Forge command line and it changes the present working directory to model.

Figure 5.11. Automated Workflow Resulting from Show In→Forge Console

4. To create the Event entity class, on the Forge command line enter entity --named Event --package org.jboss.jdf.example.ticketmonster.model

This creates a Event.java file that is automatically opened in a Java editor.

Note

The Forge console has auto-complete features. If you start typing a command, you can press Tab and Forge attempts to complete the command as far as possible. If there are multiple possible options for completing a command, all the options are output in the Forge console for you to see.

5. To define the primary key attribute of the Event entity class, on the Forge command line enter validation setup

27

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

6. To create the fields for the Event entity class, on the Forge command line enter field string --named name field string --named description field boolean --named major field string --named picture

7. To set up constraints on the accepted values of the fields of the Event entity class, on the Forge command line enter constraint NotNull --onProperty name constraint Size --onProperty name --min 5 --max 50 --message "Must be > 5 and < 50" constraint Size --onProperty description --min 20 --max 1000 --message "Must be > 20 and < 1000"

Figure 5.12. Complete Forge Output for this TicketMonster Workflow

Report a bug

5.5. Add an Entity Using Hibernate Tools

A new entity class can be added to the TicketMonster project using Hibernate Tools. In the procedure below a Venue entity class is created to hold information about the venues where events will be held.

This Venue entity has id, name, description and capacity fields.

Procedure 5.5. Add an Entity Using Hibernate Tools

1. In the Project Explorer view, expand ticket-monsterJava

28

Chapter 5. Creating the TicketMonster Application

Resourcessrc/m ain/java.

2. Right-click org.jboss.jdf.example.ticketmonster.model and click NewClass.

Figure 5.13. New→Class Menu Option

3. In the Name field, type Venue and click Finish. This creates a Venue.java file that is automatically opened in a Java editor.

29

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Figure 5.14 . Completed Name Field in Java Class Wizard

30

4. Add fields to the entity by adding the following lines in between the braces of the Venue class private Long id; private String name; private String description; private int capacity;

Chapter 5. Creating the TicketMonster Application

5. To save the Venue.java file, press Ctrl+S.

6. To add get and set methods for each field, right-click a new line after private int capacity; and click SourceGenerate Getters and Setters.

Figure 5.15. Source→Generate Getters and Setters Menu Option

7. Click Select All and click OK.

8. Save the Venue.java file.

9. To make the Venue class into an entity, right-click anywhere in the Venue class and click

SourceGenerate Hibernate/JPA annotations.

31

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Figure 5.16. Source→Generate Hibernate/JPA annotations Menu Option

10. Ensure org.jboss.jdf.example.ticketmonster.model.Venue is selected and click

Next.

11. Click Finish and save the Venue.java file.

Report a bug

5.6. Prepare Event Records to Populate the Database

This web project uses H2 for data storage by default. H2 is a Java database integrated with the application servers of JBoss Enterprise Application Platform 6. It is an in-memory database which means that the data does not persist once the application using the database stops running. For this reason, seed data must be stored in a file within the project and added to the database each time the application starts. While it might not seem practical to have to construct the database each time the application starts, this type of data storage is useful during development for testing purposes.

Warning

The use of H2 for data storage is for testing purposes only and must not be used during production.

The procedure below demonstrates preparing two sample Event records for addition to the H2 database once the TicketMonster application starts.

Procedure 5.6. Prepare Event Records

32

Chapter 5. Creating the TicketMonster Application

1. In the Project Explorer view, expand ticket-monsterJava

Resourcessrc/m ain/resources.

2. To open the import.sql file for editing, double-click the file name.

Figure 5.17. import.sql File Location

3. The file already contains one sample Member record. If your screen is small you might not be able to see the whole of the entry. Double-click the import.sql view label to make the editor fill the window.

4. To create a new Event record, type the following on one line after the existing Member record insert into Event (id, name, description, major, picture, version) values (1,

'Shane''s Sock Puppets', 'This critically acclaimed masterpiece...', true,

'http://dl.dropbox.com/u/65660684/640px-Carnival_Puppets.jpg', 1);

5. To create a second new Event record, type the following on one line after the first new Event record insert into Event (id, name, description, major, picture, version) values (2,

'Rock concert of the decade', 'Get ready to rock...', true,

'http://dl.dropbox.com/u/65660684/640px-Weir%2C_Bob_(2007)_2.jpg', 1);

33

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Figure 5.18. Content of the import.sql File for this TicketMonster Workflow

6. To save the import.sql file, press Ctrl+S.

7. To make the editor return to its previous size, double-click the import.sql view label.

Report a bug

5.7. Deploy the Application using JBoss Server Tools

The TicketMonster application can be deployed on the JBoss Enterprise Application Platform 6.x server created earlier in the tutorial. The procedure below guides you through how to do this.

Procedure 5.7. Deploy the Application Using JBoss Server Tools

1. In the Project Explorer view, right-click the ticket-monster project name and click Run

AsRun on Server.

34

Chapter 5. Creating the TicketMonster Application

Figure 5.19. Run As→Run on Server Menu Option

2. In the Run On Server wizard, ensure Choose an existing server is selected.

3. From the Select the server that you want to use table, select jboss-eap-6.x and click Finish. If not already in view, the Console view automatically opens and shows the runtime server output. Also, a Web Browser automatically opens and displays the web page of the running TicketMonster application.

35

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

36

Figure 5.20. JBoss Enterprise Application Platform 6.x Selected in Run on Server

Wizard

4. In the Web Browser, enter sample Member data in the Member Registration fields and click

Register. The submitted data is displayed in the Mem bers table, which is visible at the bottom of the web page.

Chapter 5. Creating the TicketMonster Application

Figure 5.21. Sample Data in the Member Registration Fields

Report a bug

5.8. Access and Query the Database

This web project uses the in-memory database, H2, of the application servers in

JBoss Enterprise Application Platform 6. The H2 console web application can be used to access the H2 database but this is not packaged with JBoss Enterprise Application Platform 6. As the procedure below explains, the H2 console web application must be downloaded and deployed on the application server from outside JBoss Developer Studio before the H2 database can be accessed.

Procedure 5.8. Access and Query the Database

1. Go to http://www.jboss.org/jdf/quickstarts/jboss-as-quickstart/h2-console/ .

2. Click Download and click Source zip.

37

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Figure 5.22. H2 Download Website

3. To deploy the H2 console web application, extract the contents of the downloaded file and copy the h2console.war file from the h2-console directory to the path/to/jboss-eap-

6.x/standalone/deploym ents directory. The H2 console web application immediately starts running on the JBoss Enterprise Application Platform 6.x server running the TicketMonster application. This can be confirmed by looking at the server output in the Console view in

JBoss Developer Studio.

Figure 5.23. Console Output showing h2console.war Deployed

38

4. In the IDE open a new Web Browser by clicking WindowShow ViewOther, expand

General and double-click Internal Web Browser.

5. In the address bar of the Web Browser, enter http://localhost:8080/h2console .

6. In the Login area, in the JDBC URL field type jdbc:h2:mem:ticket-monster and in both the

Chapter 5. Creating the TicketMonster Application

User Nam e and Password fields type sa. These settings are defined in the ticket-m onster-

ds.xm l file in the ticket-m onster/src/m ain/webapp/WEB-INF directory.

Figure 5.24 . Completed H2 Login Web Page

7. To connect to the database, click Connect.

8. The Event, Member and Venue entities created in the TicketMonster project are displayed under

jbdc:h2:m em :ticket-m onster. Expanding the entities shows the fields associated with each. The records stored in the database are viewed using SQL search statements. For example, to display all the Event records stored in the database, click Event, which creates a SQL search statement based on Event in the SQL statement field, and click Run. The details of the Event sample records you added to import.sql earlier in the tutorial are visible in the table below the

SQL statem ent field.

Figure 5.25. Event Records Stored in the H2 Database

Report a bug

5.9. Add a RESTful Web Service

39

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

For the TicketMonster application to be able to access the information stored in the database, web services are needed. The procedure below creates a RESTful web service that returns all the events in the database. It generates a POJO (plain old Java object) and adds JAX-RS annotations to create an endpoint.

Procedure 5.9. Add a RESTful Web Service

1. In the Project Explorer view, expand ticket-monsterJava

Resourcessrc/m ain/java.

2. Right-click org.jboss.jdf.example.ticketmonster.rest and click NewClass.

Figure 5.26. New→Class Menu Option

3. In the Name field, type EventService and click Finish. This creates a EventService.java file that is automatically opened in a Java editor.

4 0

Chapter 5. Creating the TicketMonster Application

Figure 5.27. Completed Name Field in Java Class Wizard

4. Add the following lines immediately above public class EventService {

@Path("/events")

@RequestScoped and add the following lines in between the braces of the EventService class

4 1

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

@Inject private EntityManager em;

@GET

@Produces(MediaType.APPLICATION_JSON) public List<Event> getAllEvents() {

final List<Event> results =

em.createQuery("select e from Event e order by e.name").getResultList();

return results;

}

5. To save the EventService.java file, press Ctrl+S

6. To resolve the errors relating to missing imports, right-click anywhere in the EventService class and click SourceOrganize Imports.

4 2

Figure 5.28. Source→Organize Imports Menu Option

7. For each class name that is not unique, select the class to use as follows and click Next:

For MediaType select javax.ws.rs.core.MediaType

For Event select org.jboss.jdf.example.ticketmonster.model.Event

For Produces select javax.ws.rs.Produces

For List select java.util.List

For Inject select java.inject.Inject

For RequestScoped select java.enterprise.context.RequestScoped

Chapter 5. Creating the TicketMonster Application

Figure 5.29. For MediaType Class Select javax.ws.rs.core.MediaType

8. Once all the classes have been chosen, click Finish. The import statements corresponding to the class names selected in the previous step are added to the EventService.java file.

9. Save the EventService.java file.

10. To update the deployed version of the application, in the Servers view expand jboss-eap-6.x.

Right-click ticket-monster and click Full Publish.

4 3

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Figure 5.30. Full Publish Menu Option

11. To see the output of the new RESTful endpoint, open a new Web Browser by clicking

WindowShow ViewOther, expand General and double-click Internal Web Browser.

12. In the address bar of the Web Browser, enter http://localhost:8080/ticket-monster/rest/events . In the opened file browser window, select a directory and enter a file name in which to save the

JSON output. The file can be viewed with a text editor and it contains details of the two event records created earlier in the tutorial.

Report a bug

5.10. Add a User Interface Optimized for Mobile Devices

The TicketMonster user interface displays on desktop and mobile clients but it is not optimized for the latter. The procedure below uses the jQuery Mobile API to create a mobile optimized user interface. The mobile user interface created varies from the existing user interface by displaying the names of the events returned by the previously created web service rather than the Member Registration web page.

Procedure 5.10. Add a User Interface Optimized for Mobile Devices

1. In the Project Explorer view, expand ticket-monstersrcmain.

2. Right-click webapp and click NewHTML file.

4 4

Chapter 5. Creating the TicketMonster Application

Figure 5.31. New→HTML file Menu Option

3. In the Enter or select the parent folder field, type ticket-

m onster/src/m ain/webapp.

4. In the File name field, type mobile.html and click Next.

4 5

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

4 6

Figure 5.32. Completed File Name Field in New HTML File Wizard

5. From the Templates list, select HTML5 jQuery Mobile Page and click Finish. This creates a mobile.html file that is automatically opened in the Visual/Source tab of the

Visual Page Editor.

Chapter 5. Creating the TicketMonster Application

Figure 5.33. Selected HTML5 jQuery Mobile Page Template in New HTML File Wizard

6. To list the events returned by the web service in the mobile user interface, add the following lines immediately after the alert("Ready To Go"); line

4 7

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

$.getJSON("rest/events", function(events) {

// console.log("returned are " + events);

var listOfEvents = $("#listOfItems");

listOfEvents.empty();

$.each(events, function(index, event) {

// console.log(event.name);

listOfEvents.append("<li><a href='#'>" + event.name + "</a>");

});

listOfEvents.listview("refresh");

});

4 8

Figure 5.34 . Completed mobile.html File

7. To save the mobile.html file, press Ctrl+S.

8. To view the mobile interface, open an external web browser and in the address bar enter http://localhost:8080/ticket-monster/mobile.html

. At the Ready To Go prompt, click OK. The names of the events in the database are displayed.

Note

HTML pages are deployed immediately so there is no need to do a full publish of the

TicketMonster application to see changes.

Chapter 5. Creating the TicketMonster Application

Figure 5.35. Events Displayed via Mobile Interface in External Web Browser

Report a bug

5.11. Test the Mobile User Interface Using BrowserSim

Mobile user interfaces are best tested on mobile devices and JBoss Developer Studio provides

BrowserSim for this purpose. The procedure below guides you through viewing the TicketMonster application on simulated mobile devices using BrowserSim.

Procedure 5.11. Test the Mobile User Interface Using BrowserSim

1. To view the mobile user interface with BrowserSim, on the toolbar click the BrowserSim icon .

A simulated device is displayed.

2. At the Ready To Go prompt, click Close. The names of the events in the database are displayed.

Note

If the names of the events in the database are not displayed, check the address bar of the simulated device. The address bar must state http://localhost:8080/ticketmonster/mobile.html

.

3. To rotate the mobile device, click in any corner of the simulated device.

4. To change the type of simulated device displayed, right-click anywhere on the simulated device, click Skin and select from the different skins listed.

4 9

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

50

Figure 5.36. Skin Menu Option

5. To close BrowserSim, right-click anywhere on the simulated device and click Close.

Chapter 5. Creating the TicketMonster Application

Figure 5.37. Close Menu Option

Report a bug

51

Red Hat JBoss Developer Studio 7.1 Getting Started Guide

Chapter 6. Uninstall JBoss Developer Studio

6.1. Uninstall JBoss Developer Studio

Procedure 6.1. Uninstall with the Uninstaller

1. Ensure JBoss Developer Studio is not running.

2. On the command line, navigate to path/to/JBoss Developer Studio/Uninstaller.

3. On the command line, enter java -jar uninstaller.jar

Note

Alternatively, to start the uninstaller you may be able to double-click the

uninstaller.jar file.

4. To remove the entire JBoss Developer Studio installation directory, select the Force the

deletion check box. If this is not selected, JBoss Developer Studio is uninstalled but some files are left behind in the installation directory.

5. Click Uninstall.

6. Once the progress bar shows Finished, click Quit to close the Uninstaller window.

Figure 6.1. Uninstaller in Finished State

Report a bug

52

Revision History

Revision 7.1.0-6.4 05

Rebuild with Publican 4.0.0

Tue Dec 17 2013

Revision 7.1.0-6

Published for 7.1.0.GA

Revision 7.1.0-5

Published for 7.1.0.Beta

Tue Dec 10 2013

Fri Nov 08 2013

Revision 7.1.0-4 Wed Nov 06 2013

TOOLSDOC-416: Screen captures updated for UI changes

Revision 7.1.0-3 Tue Nov 05 2013

TOOLSDOC-414: Screen captures updated

Revision 7.1.0-2 Tue Nov 05 2013

TOOLSDOC-413: JIRA links added for bug reporting

Revision 7.1.0-1

First draft

Wed Oct 09 2013

Rüdiger Landmann

Michelle Murray

Michelle Murray

Michelle Murray

Michelle Murray

Michelle Murray

Michelle Murray

Revision History

53

Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement

Table of contents