blob: 79658718bdf62b48484f2349f63207a5432bc07d [file] [log] [blame]
//
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
//
= Quick Start for NetBeans Platform 6.8 Using Maven
:jbake-type: platform_tutorial
:jbake-tags: tutorials
:jbake-status: published
:syntax: true
:source-highlighter: pygments
:toc: left
:toc-title:
:icons: font
:experimental:
:description: Quick Start for NetBeans Platform 6.8 Using Maven - Apache NetBeans
:keywords: Apache NetBeans Platform, Platform Tutorials, Quick Start for NetBeans Platform 6.8 Using Maven
Welcome to the link:https://netbeans.apache.org/platform/[*NetBeans Platform*]!
This document is a quick demonstration of how to create a simple NetBeans Platform application and module and use Maven for the build framework. In this document you will use Maven archetypes to create the NetBeans Platform application and module. You will use the Swing UI toolkit and "Matisse" GUI Builder to create a window component in the module. The modular aspect of the NetBeans Platform enables you to develop and expand the functionality of your application simply by adding new modules.
This document is based on the Ant-based link:../nbm-quick-start.html[NetBeans Platform Quick Start for NetBeans Platform 6.8]. and illustrates some of the differences between using Ant and Maven to develop NetBeans Platform applications. After you understand how Maven is different from Ant, you can easily proceed through other tutorials on the the link:https://netbeans.apache.org/kb/docs/platform.html[NetBeans Platform Learning Trail].
If you are new to the NetBeans Platform, you might want to watch the the screencast series link:https://netbeans.apache.org/tutorials/nbm-10-top-apis.html[Top 10 NetBeans APIs].
NOTE: You do not need to download a separate version of the NetBeans Platform to develop applications for the NetBeans Platform. Typically, you develop the applications and modules in the NetBeans IDE and then only include the modules that are necessary to run the NetBeans Platform and your application.
Before starting this tutorial you may want to familiarize yourself with the following documentation.
* link:http://wiki.netbeans.org/MavenBestPractices[Best Practices for Apache Maven in NetBeans 6.x]
* link:http://www.sonatype.com/books/maven-book/reference/introduction.html[Chapter 1. Introducing Apache Maven] (from link:http://www.sonatype.com/books/maven-book/reference/public-book.html[Maven: The Definitive Guide])
* link:https://netbeans.apache.org/kb/docs/java/gui-functionality.html[Introduction to GUI Building]
== Configuring Maven
If this is your first Maven project you will want to check the Maven configuration settings in the Options window. To complete this tutorial you must have Maven installed on your local system. You can download the installer from the link:http://maven.apache.org/[Maven site].
[start=1]
1. Select the Miscellaneous category in the Options window and click the Maven tab.
[start=2]
1. Specify the location of your local Maven installation (requires 2.0.9 or newer).
[start=3]
1. Check that the location of the local Maven repository is correct.
[start=4]
1. Click OK.
The IDE uses your local Subversion client to retrieve Maven artifacts from remote repositories. You might want to check that a Subversion client is installed and configured correctly by typing ``svn --version`` on the command line.
For details on setting up Subversion, see the link:https://netbeans.apache.org/kb/docs/ide/subversion.html[Guided Tour of Subversion].
=== Viewing the Maven Repositories
The artifacts that are used by Maven to build all your projects are stored in your local Maven repository. When an artifact is declared as a project dependency, the artifact is downloaded to your local repository from one of the registered remote repositories.
The NetBeans repository and several well-known indexed Maven repositories are registered and listed in the Repository Browser window by default. The NetBeans repository contains most of the public artifacts necessary for you to build your project. You can use the Maven Repository Browser to view the contents of your local and remote repositories. You can expand the Local Repository node to see the artifacts that are present locally. The artifacts listed under the NetBeans repository nodes can be added as project dependencies, but not all of them are present locally. They are only added to the Local Repository when they are declared as project dependencies.
To open the Maven Repository Browser:
* Choose Window > Other > Maven Repository Browser from the main menu.
image::images/maven-quickstart68_maven-nbm-netbeans-repo.png[title="Screenshot of Maven Repository Browser"]
When your cursor is over an artifact, the IDE displays a tooltip with the artifact's coordinates. You can view additional details about an artifact by double-clicking the artifact's JAR file in the browser.
You can search for an artifact by clicking the Find button in the toolbar of the Maven Repository Browser or by using the Quicksearch textfield in the main toolbar.
For more about managing Maven classpath dependencies and working with Maven repositories in the IDE, see the link:http://wiki.netbeans.org/MavenBestPractices#Dependency_management[Dependency Management] section of link:http://wiki.netbeans.org/MavenBestPractices[Best Practices for Apache Maven in NetBeans 6.x].
To see a demonstration of using the Artifact Viewer, see the link:https://netbeans.apache.org/kb/docs/java/maven-dependencies-screencast.html[ Working with Maven Dependencies] screencast.
== Creating the NetBeans Platform Application Project
In this section you use the New Project wizard to create a NetBeans Platform Application from a Maven archetype. The wizard will create the Maven module projects that you need to develop a NetBeans Platform application. The wizard also creates a sample module that provides an example of how the Maven projects are configured. In this quickstart you will modify the default sample module, but you can delete the sample module when you develop your own applications.
Perform the following steps to create the NetBeans Platform application using the New Project wizard.
[start=1]
1. Choose File > New Project (Ctrl-Shift-N) to open the New Project wizard.
[start=2]
1. Select Maven Project from the Maven category. Click Next.
[start=3]
1. Select Maven NetBeans Platform Application Archetype. Click Next.
[start=4]
1. Type *MavenPlatformWordApp* for the Project Name and set the Project Location. Click Finish.
image::images/maven-quickstart68_maven-nbm-newprojectwizard1.png[title="Screenshot of New Project wizard"]
*Note.* If this is your first NetBeans Platform application using Maven, it can take some time to create the projects because the IDE needs to download any necessary artifacts from the NetBeans repository.
When you click Finish, by default the IDE creates the following Maven project types.
* *NetBeans Platform Application.* This project is a container project for the Platform application and lists the modules to include and the location of the project's repositories. This project does not contain any sources. The IDE generates the modules containing the sources and resources in sub-directories of this project.
* *NetBeans Platform based application.* This project specifies the artifacts (sources) needed for compiling the application. The required dependencies (IDE artifacts, module artifacts) are specified in the ``pom.xml`` file of the project.
* *Platform application branding resources.* This project contains the resources used for branding the application.
* *sample NetBeans Module.* This project is created by default as an example of a module of a platform application. This project is not required to compile the application. When you develop your application you can delete this module and remove the module as a dependency.
image::images/maven-quickstart68_maven-nbm-projectswindow1.png[title="Screenshot of project structure in Projects window"]
When you create the project, you will see that some of the projects (for example, the NetBeans Platform based application project) are badged because some dependencies declared in the ``pom.xml`` file (POM) are unavailable. For all Maven projects, the POM is located under the Project Files node in the Projects window.
*Note.* If the branding module appears as ``<Badly formed Maven project>`` in the Projects window, right-click the project in the Projects window and choose Reload Project. See link:http://wiki.netbeans.org/MavenMissingExtensionPluginError[MavenMissingExtensionPluginError].
If you look at the POM of the NetBeans Platform based application generated by the wizard, you can see that by default the sample module artifact ( ``module1`` ) is listed as a required dependency for compiling the application. The artifact will be available after you build the sample module project and install the artifact in your local repository.
[source,xml]
----
<dependency>
<groupId>com.mycompany</groupId>
<artifactId>*module1*</artifactId>
<version>1.0-SNAPSHOT</version>
<type>nbm</type>
</dependency>
----
If you look at the POM for the sample module you see that the project has the ``artifactId`` *module1*.
[source,xml]
----
<parent>
<groupId>com.mycompany</groupId>
<artifactId>MavenPlatformWordApp</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>*module1*</artifactId>
<packaging>nbm</packaging>
<version>1.0-SNAPSHOT</version>
<name>MavenPlatformWordApp - sample NetBeans Module</name>
----
The sample module is a NetBeans module. To build a NetBeans module you need to use the ``nbm-maven-plugin`` . If you look at the POM for the sample module, you can see that the IDE automatically specified the plugin to use to build the project as a NetBeans module.
[source,xml]
----
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>*nbm-maven-plugin*</artifactId>
</plugin>
----
If you look at the POM for the NetBeans Platform Application, you can see that *module1* is listed as one of the modules in the application.
[source,xml]
----
<modules>
<module>*module1*</module>
<module>branding</module>
<module>application</module>
</modules>
----
== Modifying the Sample Module
In this section you will modify the sample module to add a window component and a button and text area.
=== Adding a Window Component to the Sample Module
In this exercise you will use a wizard to add a Window Component to the sample module.
[start=1]
1. Right-click *MavenPlatformWordApp - sample NetBeans Module* in the Projects window and choose New > Other to open the New File wizard.
[start=2]
1. Select Window Component in the Module Development category. Click Next.
[start=3]
1. Select *output* in the Window Position dropdown list. Click Next.
[start=4]
1. Type *Text* in the Class Name Prefix field. Click Finish.
The wizard displays a list of the files that will be created and the files that will be modified.
image::images/maven-quickstart68_maven-nbm-newwindowcomponent-sample.png[title="Screenshot of window component page in New File wizard"]
When you click Finish, in the Projects window you can see that the IDE generated the classes ``TextAction.java`` and ``TextTopComponent.java`` in ``com.mycompany.mavenplatformwordapp`` under Source Packages. The IDE also generated additional resource files in ``com.mycompany.mavenplatformwordapp`` under Other Sources. In this exercise you will only edit ``TextTopComponent.java`` so you can close the other files.
You can view the structure of the project in the Files window. To compile a Maven project, only Java files can be located under Source Packages ( ``src/main/java`` directory in the Files window). Non-Java files (e.g., XML files) need to be located under Other Sources ( ``src/main/resources`` directory in the Files window).
=== Modifying the Window Component
You will now add the text area and button elements to the window component by performing the following steps.
[start=1]
1. Click the Design tab of ``TextTopComponent.java`` in the editor.
[start=2]
1. Drag and drop a button and a text area from the Palette onto the window.
[start=3]
1. Right-click the text area and choose Change Variable Name, and then type *text* as the name. You will use the name when accessing the component from your code.
[start=4]
1. Set the text of the button to "*Filter!*".
image::images/maven-quickstart68_maven-nbm-textopcomponent.png[title="Screenshot of window component page in New File wizard"]
[start=5]
1. Double-click the Filter! button element in the Design view to open the event handler method for the button in the source code editor. The method is created automatically when you double-click the button element.
[start=6]
1. Modify the body of the method to add the following code and save your changes.
[source,java]
----
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
*String s = text.getText();
s = s.toUpperCase();
text.setText(s);*
}
----
You can use the code completion in the editor to help you type the code.
=== Building and Running the Application
[start=1]
1. Right-click the project node of the *MavenPlatformWordApp NetBeans Platform based application* and choose Build with Dependencies.
The default action mapped to Build with Dependencies is to build the project using the Reactor plugin. When you build a project using the Reactor plugin, the dependencies of the sub-projects are built before the containing project is built. The Output window displays the build order.
image::images/maven-quickstart68_maven-nbm-buildoutput1.png[title="Screenshot of Reactor build order in Output window"]
The results of the build are also displayed in the Output window.
image::images/maven-quickstart68_maven-nbm-buildoutput2.png[title="Screenshot of successful Reactor build in Output window"]
If you look at the Projects window, you will see that the projects no longer have badges because the artifacts of the required dependencies are now in the Local repository under the ``com.mycompany`` node.
image::images/maven-quickstart68_maven-nbm-localrepo.png[title="Screenshot of Local repository"]
[start=2]
1. Right-click the project node of the *MavenPlatformWordApp NetBeans Platform based application* and choose Run.
When you Run the application, the IDE launches the NetBeans Platform 6.7 application. To test the application, perform the following steps:
[start=1]
1. Choose Window > Text from the main menu of the platform application.
image::images/maven-quickstart68_maven-nbm-wordapp.png[title="Screenshot of Text window in application"]
[start=2]
1. Type some characters in the text area and click Filter!
When you click Filter!, the characters that you typed are changed to upper case and displayed in the text area.
== Updating the Platform Version and Splash Image
The archetype that you used to create the application specifies 6.7 as version of the platform. In this section you will update the version of the NetBeans Platform to 6.8 and change the splash screen that appears when you launch the application.
=== Updating the Platform Version in NetBeans Platform Application
In this exercise you will update the POM file to specify the NetBeans 6.8 version of the artifacts.
[start=1]
1. Expand the *MavenPlatformWordApp NetBeans Platform Application* project node in the Projects window.
[start=2]
1. Expand the Project Files node and double-click ``pom.xml`` to open the POM in the editor.
[start=3]
1. Modify the ``<netbeans.version>`` element to change the version to ``RELEASE68`` and save your changes.
[source,xml]
----
<properties>
<netbeans.version>*RELEASE68*</netbeans.version>
<brandingToken>foo</brandingToken>
</properties>
</project>
----
=== Updating the Dependencies in NetBeans Platform based application
In this exercise you will update the POM file to change the artifact for the IDE cluster to platform11.
[start=1]
1. Expand the *MavenPlatformWordApp NetBeans Platform based application* project node in the Projects window.
[start=2]
1. Expand the Project Files node and double-click ``pom.xml`` to open the POM in the editor.
[start=3]
1. Modify the ``<artifactId>`` element to change the version to ``platform11`` and save your changes.
[source,xml]
----
<dependency>
<groupId>org.netbeans.cluster</groupId>
<artifactId>*platform11*</artifactId>
<version>${netbeans.version}</version>
<type>pom</type>
</dependency>
----
=== Replacing the Splash Screen
In this exercise you will replace the default splash image that is displayed when you launch the application. By default the branding module generated by the IDE contains an image that is used as the splash image. You can replace this with a different image by performing the following steps.
[start=1]
1. Locate the default splash image ( ``splash.gif`` ) in the following directory of the *MavenPlatformWordApp Platform application branding resources* module project.
* In the Projects window: ``Other Sources > nbm-branding > core > core.jar > org > netbeans > core > startup``
* In the Files window: ``src > main > nbm-branding > core > core.jar > org > netbeans > core > startup``
[start=2]
1. Replace the default image with an image named ``splash.gif`` .
The default size of the splash image is 473 x 300. For example, you can copy the image below to the ``startup`` directory.
image::images/maven-quickstart68_splash.gif[title="Example of default splash image"]
=== Building and Running the Application
You can now build and run the NetBeans Platform application again by performing the same steps as before.
[start=1]
1. Right-click the project node of the *MavenPlatformWordApp NetBeans Platform based application* and choose Clean.
[start=2]
1. Right-click the project node of the *MavenPlatformWordApp NetBeans Platform based application* and choose Build with Dependencies.
[start=3]
1. Right-click the project node of the *MavenPlatformWordApp NetBeans Platform based application* and choose Run.
When you click Run, you can see in the Output window the the IDE now builds the standalone NetBeans Platform application using the NetBeans Platform 6.8 cluster ``Platform11`` .
image::images/maven-quickstart68_maven-nbm-runupdated.png[title="Screenshot of Local repository"]
The application also displays the new splash image when the application starts.
This quickstart demonstrated how creating a NetBeans Platform application using Maven is not very different from creating an application using Ant. The major difference is understanding how the Maven POM controls how the application is assembled. For more examples on how to build NetBeans Platform applications and modules, see the tutorials listed in the link:https://netbeans.apache.org/kb/docs/platform.html[NetBeans Platform Learning Trail].
There will soon be more examples that demonstrate how to use Maven to build NetBeans Platform applications.
If you have any questions about the NetBeans Platform, feel free to write to the mailing list, dev@platform.netbeans.org, or view the link:https://mail-archives.apache.org/mod_mbox/netbeans-dev/[NetBeans Platform mailing list archive].