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

environments. Bare repositories differ from normal repositories because they do not contain a working or checked out copy of any source files. This prevents editing files and committing changes in the repository. Additionally, they store the git revision history for your repository in the repository’s root folder instead of in a .git sub-folder.

When selecting the files to commit in the Commit Changes, you can select only the files you want included in the commit using the checkboxes next to each file name. The unchecked files are not included in the commit and no extra actions are required to reconcile the uncommitted files when committing and creating a Pull Request.

If you need to add a change ID to each commit message, in the Comming Changes dialog box, click the rightmost icon at the top right corner to add a change ID to the commit message.

1.2. CONFIGURING MAVEN BASICS

In the context of application development, Maven provides a standardized build system for projects.

One of the main benefits of using Maven with your project is that it facilitates fetching dependencies from one or more repositories. This article serves as an introduction to using Maven with the IDE and contains instructions for the following tasks:

1.

Section 1.2.1, “Creating a New Maven Project”

2.

Section 1.2.2, “Creating a New Maven Module”

3.

Section 1.2.3, “Adding Maven Support to an Existing Non-Maven Project”

Root Maven projects can serve as aggregators for multiple Maven modules, also known as subprojects. For each module that is part of a maven project, a <module> entry is added to the project’s pom.xml file. A pom.xml that contains <module> entries is often referred to as an aggregator pom.

When modules are included into a project it is possible to execute Maven goals across all of the modules by a single command issued from the parent project directory.

Note

Note that the provided instructions pertain to the creation of a parent+module project structure. If you prefer to create just a simple project, simply start with an archetype or don’t use the pom packaging in step 2.a.

16

1.2.1. Creating a New Maven Project

Use the following instructions to create the parent project of a multi-module Maven project. The instructions provided ensure that the packaging option is set to pom, which is a requirement for multi-module Maven projects. Alternately, to create a standalone Maven project instead, set the packaging option to an option other than pom.

1. Create a new project: a. In the workspace, navigate to FileNewOther.

b. Type maven in the Filter field and select Maven Project.

c. Click Next to continue.

CHAPTER 1. SETTING UP AND MANAGING A REPOSITORY FOR YOUR PROJECTS

2. Enter the initial project details: a. Check the Create a simple project (skip archetype selection) check box. If this check box is selected, the Select an Archetype step of the wizard is skipped and the project type is set to pom, which is required to create a

Maven Module based on this Maven project. Alternately, to create a standalone project, uncheck the Create a simple project (skip archetype

selection) check box and follow the instructions in the wizard.

b. Ensure that the Use default Workspace location check box is not checked and specify a non-default location for your workspace files using the Browse button. Using a non-default workspace location is recommended because this allows other tools to access the workspace location easily.

c. The following optional steps are available for further configuration, if required: i. (Optional) Check the Add project(s) to working set check box to add the newly created projects to a working set.

ii. (Optional) Click Advanced to view additional optional advanced configuration for the new Maven project, such as:

A. Resolve Workspace projects: dependencies opened as workspace projects will be resolved without having to install them to your local Maven repository first. This way, any changes made to one of these dependencies will have an immediate effect on other projects consuming it (compilation, refactoring, etc.). When

Resolve Workspace projects is disabled, dependencies existing in the workspace must be installed to your local Maven repository after any change (by running mvn install), in order to see effects in projects consuming them.

B. Profiles: select a set of Maven profiles to activate or deactivate in the workspace. Profiles are defined in the project pom.xml, or inherited from a parent pom.xml, or defined in the relevant

settings.xml.

C. Name templates: allows you to disambiguate projects names in the workspace by prepending or appending the group ID or SCM branch names to the default artifact ID.

Figure 1.16. Create a New Maven Project

17

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

18

d. When the configuration is complete, click Next to continue.

3. Configure the project details: a. Enter the desired group ID, which is similar to an organization namespace (for example, com.company.businessunit.project), in the Group Id field.

b. Enter the desired artifact ID value, which is the name for your project, in the

Artifact Id field. This value must not include any spaces and the only special characters allowed are periods ('.'), underscores ('_'), and dashes ('-').

c. Set the Version field’s value to 0.0.1-SNAPSHOT or a similar value. For details about the appropriate version build numbers, see Project Versions d. Set the value of the Packaging field to pom.

e. (Optional) Add a name for your project in the Name field.

f. (Optional) Add a description for your project in the Description field.

Figure 1.17. Configure Project Details

CHAPTER 1. SETTING UP AND MANAGING A REPOSITORY FOR YOUR PROJECTS

g. Click Finish to conclude the new Maven project creation wizard.

Result: Your new Maven project is created and appears in the Project Explorer view.

1.2.2. Creating a New Maven Module

Each Maven project with a packaging pom can include multiple Maven modules. Follow the instructions to create your first Maven module:

1.2.2.1. Prerequisites

1. You must have an existing Maven project available with the packaging type pom. See

Create a New Maven Project for instructions to create a new Maven project.

1.2.2.2. Creating a New Maven Module

1. Create a new Maven module as follows: a. In the Project Explorer view, right-click the recently created pom project and select

NewProject.

b. From the wizard selection screen, expand Maven and select Maven Module.

c. Click Next > to continue.

19

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

2. Enter the initial module details: a. Ensure that the Create a simple project (skip archetype

selection) check box is not checked. If this check box is selected, the Select

an Archetype step of the wizard is skipped.

b. Enter the desired module name in the Module Name field. This value corresponds to the Maven project’s Project ID.

c. Use the Browse button to locate the desired parent project and select it.

d. The following optional steps are available for further configuration, if required: i. (Optional) Check the Add project(s) to working set check box to add the newly created projects to a working set.

ii. (Optional) Click Advanced to view additional optional advanced configuration for the new Maven project, such as:

A. Resolve Workspace projects: dependencies opened as workspace projects will be resolved without having to install them to your local Maven repository first. This way, any changes made to one of these dependencies will have an immediate effect on other projects consuming it (compilation, refactoring, etc.). When

Resolve Workspace projects is disabled, dependencies existing in the workspace must be installed to your local Maven repository after any change (by running mvn install), in order to see effects in projects consuming them.

B. Profiles: select a set of Maven profiles to activate or deactivate in the workspace. Profiles are defined in the project pom.xml, or inherited from a parent pom.xml, or defined in the relevant

settings.xml.

C. Name templates: allows you to disambiguate projects names in the workspace by prepending or appending the group ID or SCM branch names to the default artifact ID.

Figure 1.18. Set the Module Name and Parent

20

CHAPTER 1. SETTING UP AND MANAGING A REPOSITORY FOR YOUR PROJECTS

e. When the configuration is complete, click Next to continue.

3. Enter the module archetype information: a. Ensure that the Show the last version of Archetype only check box is checked. This ensures that only the latest version of each archetype displays.

b. Select an archetype based on the purpose of the project you are creating. Use the keyword maven-archetype-quickstart in the Filter field to locate a sample

Maven project archetype.

Figure 1.19. Select a Module Archetype

21

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

c. Click Next to continue.

4. Enter the module details: a. Add the same group ID value that was used for the Maven project to the Group Id field.

b. Add the desired version number in the Version field. For details about the appropriate version build numbers, see Project Versions c. The Artefact Id and Package fields are automatically populated based on the parent project details.

Figure 1.20. Configure the Module Archetype Parameters

22

CHAPTER 1. SETTING UP AND MANAGING A REPOSITORY FOR YOUR PROJECTS

d. Click Finish to conclude setting up the Maven module.

5. (Optional) To change the settings for the created Maven module, expand the module name in the Project Explorer view and double click pom.xml from the expanded list. An

Overview tab appears and all settings can be changed from this tab.

Figure 1.21. Change the Module Settings from the Overview View

Result: Your new Maven module is created and appears in the Project Explorer view.

Additionally, a hierarchical view of the nested projects is now available in the Project

Explorer view as well (see Nested/Hierarchical view of projects ).

1.2.3. Adding Maven Support to an Existing Non-Maven Project

The previous tasks contain instructions to create a new Maven project and Maven module.

However, for an existing application that was not created with Maven support, use the following instructions to add Maven support to the non-Maven project:

1. Right-click the project name in the Project Explorer view.

2. From the displayed options, click Configure.

3. From the displayed sub-menu, click Convert to Maven Project.

4. Configure details for the new pom file: a. The basic fields for the new pom file are prepopulated based on the project details.

If required, edit the existing values.

b. (Optional) Add a name for the new project in the Name field.

c. (Optional) Add a brief description for the project in the Description field.

Figure 1.22. Create a New Pom Descriptor

23

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

24

d. Click Finish to finalize the pom information.

5. If the project references java dependencies, a wizard appears displaying all these dependencies and a green check mark when each dependency is identified. Learn more

about dependency identification in the Did You Know section.

6. Check the Delete original references from project check box to avoid retaining duplicate or stale dependencies in your project.

Figure 1.23. Identify Maven Dependencies

CHAPTER 1. SETTING UP AND MANAGING A REPOSITORY FOR YOUR PROJECTS

7. Click Finish when all dependencies are converted.

Result: The existing project is now configured for Maven support.

1.2.4. Did You Know?

The wizard used to convert a non-Maven project to a Maven project attempts to identify all the project’s classpath entries and their equivalent Maven dependencies. From the list of identified dependencies, users can select which ones will be added to the generated Maven pom.xml file.

When identifying dependencies, one of several strategies may be used:

Checking if the jar contains the relevant maven metadata.

Identify the dependency using the Nexus indexer.

Identify the dependency using the JBoss Nexus instance REST API (if we are online) via a

SHA1 search.

Identify the dependency using the

search.maven.org

REST API (if we are online) via a

SHA1 search.

All unchecked dependencies will be ignored and are not added to the generated pom.xml.

However, some of these can be added as transitive dependencies to your project. For instance, if you add jsp-api but remove servlet-api, the latter appears in the project classpath, as it is a dependency of jsp-api.

25

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

You can double-click on a dependency from a list (or click the Edit button) to edit its Maven coordinates or scope. Selecting several dependencies (ctrl+click) and clicking the Edit button allows batch editing of their scope.

1.2.5. Troubleshooting

1. Error Message: Unidentifiable Dependency in the Maven Dependency column.

Figure 1.24. Unidentifiable Dependency

26

a. Issue: Either: i. the jar file is corrupted/invalid.

ii. the jar file is valid but does not contain any metadata used for identification.

b. Resolution: i. Make sure that jar exists as a Maven artifact. If needed, you can install it to your local repository and then Click on the Identify dependencies button.

ii. Double click on the dependency, or click on the Edit…​ button and set the expected maven coordinates.

2. Error Message: Some selected dependencies can not be resolved. Click here to configure repositories in your settings.xml.

Figure 1.25. Dependencies Can Not Be Resolved Error

CHAPTER 1. SETTING UP AND MANAGING A REPOSITORY FOR YOUR PROJECTS

a. Issue:: This error displays when a dependency can be identified (that is, whether it contains the pom properties or other metadata) but the dependency is not available in any repository defined in your settings.xml.

b. Resolution: Click the here link in the error message and compare the old and new settings for the dependency and add a new and correct repository. Users may choose to use one of the predefined repositories from Red Hat.

27

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