Red Hat JBoss Developer Studio 10.2 Getting Started with JBoss

Red Hat JBoss Developer Studio 10.2 Getting Started with JBoss

Red Hat JBoss Developer Studio 10.2 Getting Started with JBoss Developer Studio Tools

After either creating a new Node.js project or importing an existing one and then running the project, some errors may appear. JBoss Developer Studio includes a debugger to help identify and resolve these issues. To use the debugging feature:

1. Start the debugger for your project: a. In the Project Explorer view, expand your project.

b. Right-click the index.js file for your project and click Debug AsNode.js

Project.

c. Select the Remember my decision check box in the dialog box to apply your selection to subsequent perspective shifts and then click Yes or No to continue.

2. Review the elements of your project’s JavaScript files to locate errors in one of two ways: a. Expand any variable listed in the Variables tab to view additional objects and edit the details for each item.

b. Hover the mouse cursor over any variables in the index.js tab to view and edit its property details.

3. Make changes to the files to address the errors: a. Edit the index.js file in the appropriate view.

b. Save the changes. The Console view runs the updated file and displays changes.

4. After debugging the errors, use the Resume, Suspend, and Terminate buttons (

) as follows to test your changes: a. The Resume button (green triangle) continues running the project files.

b. The Suspend button (two yellow rectangles) temporarily stops running the project files to allow users to make changes.

c. The Terminate button (red square) ends the running of the project files.

5. Repeat steps 4 through 6 as necessary to locate and fix errors found by the debugger.

6. When debugging is concluded, click WindowShow ViewOther and select Project

Explorer from the options. This displays the list of projects again.

Result: You have debugged your application and returned to the Project Explorer view.

2.3. DEVELOPING APPLICATIONS USING THE FORGE TOOL

Red Hat JBoss Developer Studio offers Forge Tools for developing Java EE applications and to extend the IDE functionality in Eclipse. Start developing Java EE applications using either the Forge context menu or the command line from the IDE.

2.3.1. Creating a New Project

40

CHAPTER 2. DEVELOPING FIRST APPLICATIONS WITH JBOSS DEVELOPER STUDIO TOOLS

After you have created a Forge project you can set up persistence, add entities and fields, and create scaffold for the project.

To create a new project:

1. Press Ctrl+4 to start Forge and open the JBoss Forge context menu.

2. Click Project:New to open the Create a new project window.

3. In the Create a new project window: a. In the Project name field, type a project name.

b. In the Top level package field, type {com.example} as the top package.

c. In the Project location field, enter a target location for the Forge project.

d. In the Stack list, click Java EE 7.

4. Click Finish.

Figure 2.9. Create a New Forge Project

41

Red Hat JBoss Developer Studio 10.2 Getting Started with JBoss Developer Studio Tools

42

Result: The project is listed in the Project Explorer view.

2.3.2. Setting Up Persistence

Setting up the JPA prerequisites, creates the persistence.xml file in the project and adds the required dependencies to the pom.xml file.

Note: While creating the JPA entity, the Forge console automatically detects any prerequisites that must be set up and prompts you to create those at runtime.

To set up persistence:

1. Press Ctrl+4 to open the JBoss Forge context menu.

2. Click JPA: New Entity. The window is populated with default values.

3. Click Next to continue using the default values or edit the fields to change the values.

CHAPTER 2. DEVELOPING FIRST APPLICATIONS WITH JBOSS DEVELOPER STUDIO TOOLS

4. In the Configure your connection settings window, ensure that the fields display the appropriate values and then click Next.

5. In the Create a new JPA entity window: a. In the Package Name field, type the package name.

b. In the Type Name field, type a name for the new entity.

6. Click Finish.

Result: The new entity appears in the JBoss editor and is also listed in the Project Explorer view with the name: .java.

Figure 2.10. .java Displayed in the JBoss Editor

2.3.3. Adding Fields to the Entity

To add fields to the entity:

1. Press Ctrl+4 to open the JBoss Forge context menu.

2. Click JPA: New Field.

3. In the Create a new field window:

43

Red Hat JBoss Developer Studio 10.2 Getting Started with JBoss Developer Studio Tools

a. In the Target Entity field, select {package_name.model.entity}. b. In the Field Name field, type FirstName.

4. Click Finish.

Figure 2.11. Add Field to the Entity

44

5. Repeat steps 1 through 4 to add more fields to the entity.

Result: The fields are added to the Customer.java file.

2.3.4. Creating a Scaffold

Scaffolding is automatic code generation by a program, using available information, usually a database to generate a basic CRUD (create, read, update, delete) admin interface. The Scaffold

Generate command is used to create the scaffold.

To create the scaffold:

1. Press Ctrl+4 to open the JBoss Forge context menu.

2. Click Scaffold Generate.

3. In the Scaffold Type list, click Angular JS and then click Next.

4. If your project is not configured to use all the technologies that you want to use, Forge

prompts you to set up the dependencies. Click Next.

5. In the Select JPA entities window: a. Select the check box in the Targets field. b. Select the Generate REST resources check box.

CHAPTER 2. DEVELOPING FIRST APPLICATIONS WITH JBOSS DEVELOPER STUDIO TOOLS

6. Click Finish.

Figure 2.12. Select JPA Entities to Create the Scaffold

Result: The entities are created and listed in the Project Explorer view.

2.3.5. Running and Testing the Application

In this example we use the JBoss EAP server to run the application.

To run the application:

1. In the Project Explorer view, right-click the application and click Run AsRun on

Server. Alternatively, drag and drop the application from the Project Explorer view to the JBoss EAP 1 server in the Servers view. The application opens in the default browser.

2. Click Customers and then click Create to create a new customer.

3. In the FirstName and the LastName fields, enter the first and last names and click Save.

The customer is added to the application.

Use the Search for Customers section to search for customers by their first and/or last names.

2.3.6. Creating Extensions or Add-ons

The add-ons/extensions run inside the IDE. After adding commands and features to the add-on, no further changes are required for the extensions or add-ons to run in another IDE.

To create an add-on:

1. Press Ctrl+4 to open the JBoss Forge context menu.

2. Click Project:New.

3. In the Create a new project window: a. In the Project name field, type a name for the add-on.

45

Red Hat JBoss Developer Studio 10.2 Getting Started with JBoss Developer Studio Tools

b. In the Project type list, click Forge Addon (JAR).

4. Click Next.

5. In the Furnace Addon Setup window, Depend on these addons section, Forge

automatically selects the prerequisites. Review the dependencies and click Finish.

6. Press Ctrl+4 to open the Forge context menu.

7. Select Java: New Class to open the Java: New Class window.

8. In the Type Name field, type CustomCommand and click Finish. The

CustomCommand.java file opens in the JBoss editor.

9. To change this Java class into a Forge command: a. Press Ctrl+4 to open the Forge context menu. b. Select Addon: New UI Command to open the Generates a UICommand

implementation window.

c. In the Generates a UICommand implementation window: i. In the Type Name field, type CustomCommand. ii. In the Command name field, type custom. d. Click Finish.

Figure 2.13. Add a Command

46

CHAPTER 2. DEVELOPING FIRST APPLICATIONS WITH JBOSS DEVELOPER STUDIO TOOLS

The command is listed in the CustomerCommand.java file.

10. Press Ctrl+4 to open the Forge context menu.

11. Select Build and Install an Addon to open the Build and install a Forge

addon window.

12. Click Finish to install the add-on into the IDE.

13. To execute the installed command: a. Press Ctrl+4 to open the Forge context menu. b. Select custom. c. Add parameters to the method in order to add user input to the command. Copy

and paste the following command in the CustomCommand.java file: package org.jboss.forge.addon.commands; import org.jboss.forge.addon.configuration.Configuration; import org.jboss.forge.addon.resource.URLResource; import org.jboss.forge.addon.ui.command.AbstractUICommand; import org.jboss.forge.addon.ui.context.UIBuilder; import org.jboss.forge.addon.ui.context.UIContext; import org.jboss.forge.addon.ui.context.UIExecutionContext; import org.jboss.forge.addon.ui.input.UIInput;

47

Red Hat JBoss Developer Studio 10.2 Getting Started with JBoss Developer Studio Tools

import org.jboss.forge.addon.ui.metadata.UICommandMetadata; import org.jboss.forge.addon.ui.metadata.WithAttributes; import org.jboss.forge.addon.ui.util.Metadata; import org.jboss.forge.addon.ui.util.Categories; import org.jboss.forge.addon.ui.result.Result; import org.jboss.forge.addon.ui.result.Results; import java.lang.Override; import java.lang.Exception; import javax.inject.Inject; public class JIRASetupCommand extends

AbstractUICommand

{

@Inject

@WithAttributes(label = "JIRA URL" , required

= true ) private UIInput<URLResource> url;

@Inject private Configuration config;

@Override public UICommandMetadata getMetadata(UIContext context)

{ return Metadata.forCommand(getClass())

.name( "JIRA: Setup" )

.description( "Setup the JIRA Addon" )

.category(Categories.create( "JIRA" ,

"Setup" ));

}

@Override public void initializeUI(UIBuilder builder) throws

Exception

{

builder.add(url);

}

@Override public Result execute(UIExecutionContext context)

{

String targetUrl = url.getValue().getFullyQualifiedName();

Configuration subset = config.subset( "jira" );

subset.setProperty( "url" , targetUrl); return Results.success( "JIRA URL set to:

" +targetUrl);

}

}

48

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