Mastering Netbeans - David Salter - E-Book

Mastering Netbeans E-Book

David Salter

0,0
29,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

With the increasing complexity of software development and the abundance of tools available, learning your IDE in-depth will instantly increase your developer productivity. NetBeans is the only IDE that can be downloaded with Java itself and provides you with many cutting edge features not readily available with many IDEs. The IDE also provides a great set of tools for PHP and C/C++ developers. It is free and open source and has a large community of users and developers around the world.
This book will teach you to ace NetBeans IDE and make use of it in creating Java business and web services. It will help you to become a proficient developer and use NetBeans for software development. You will learn effective third-party interaction and enable yourself for productive database development.
Moving on, you will see how to create EJB projects and write effective and efficient web applications. Then you will learn how to use Swing and manage and configure a relational database. By the end of the book, you will be able to handle external services such as databases, Maven repositories, and cloud providers, and extend your NetBeans when you require more from your IDE.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 328

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Mastering NetBeans
Credits
About the Author
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
Questions
1. Getting Started with NetBeans
Choosing a download bundle of NetBeans
Downloading and installing NetBeans
Installing other versions of NetBeans
NetBeans user directory
Updating NetBeans to the latest version
Obtaining the NetBeans source code
Downloading a zipped archive of the NetBeans source code
Cloning the NetBeans source code from Mercurial
Cloning specific versions of NetBeans
Cloning the NetBeans source code from within NetBeans
Browsing the NetBeans source code online
Building NetBeans
Building NetBeans via the command line
Building NetBeans from within NetBeans
NetBeans configuration
User and cache directories
NetBeans default options
NetBeans JDK
Additional module clusters
Further options
Summary
2. Editing Files and Projects
The NetBeans screen layout
The explorer style windows
The Favorites window
The Navigator window
The source code editor window
The History view
The Palette window
The Properties window
The Output window
Window management
Specifying default templates for files
Code templates and code snippets
Inserting code using code templates
Code snippets – the NetBeans Palette window
Deleting palette items – the Palette Manager
Editing palette items
Macro recording and playback
Assigning shortcuts for macro playback
Recording new macros
Splitting windows
Code folds
Project groups
Summary
3. The NetBeans Developer's Life Cycle
Running applications
Debugging applications
Breakpoints
The Variables debug window
The Watches window
Evaluating expressions
The Call Stack window
The Loaded Classes window
The Sessions window
The Threads window
The Sources window
The Debugging window
Deadlock detection
Analyze Stack Window
Variable formatters
Debugging remote applications
Profiling applications
Application monitoring
Performance monitoring
Memory monitoring
Testing applications
Code coverage
Performing TDD within NetBeans
Summary
4. Managing Services
Databases
Connecting to Java DB
Connecting to MySQL
Connecting to other databases via JDBC
Managing databases

Web Services
Application Servers
Maven Repositories
Cloud services
Hudson Builders
Task Repositories
Summary
5. Database Persistence
Java EE Persistence
JPA entities
Creating blank entity classes
Editing the persistence.xml file
Creating entity classes from databases
Creating JPA controllers for entities
Creating database scripts from entity classes
Summary
6. Desktop Development
Java Swing applications
Creating Swing frames
Designing Swing forms
Anchoring and autoresizing components
Defining properties and events
Editing properties
Editing bindings
Advanced binding properties
Converters
Validators
Editing events
Editing code
Creating connections
JavaFX applications
JavaFX Scene Builder
Summary
7. Creating the Business Layer
Creating enterprise projects
Creating a NetBeans multi-module project
A Maven multi-module project
Creating a Maven multi-module project
Creating EJBs
Creating a session bean façade for entity classes
The Java Bean Validation framework
Creating a Bean Validation constraint
Contexts and Dependency Injection
Adding CDI support
CDI injection points editor support
Summary
8. Creating the Web Tier
Creating web projects
Configuring application servers
Creating a web application
Creating a NetBeans web application
Modifying a NetBeans web application
Creating a Maven web application
The web project's Run options
Adding components to a web application
Creating Spring web applications
Changing the version of Spring used
Spring application development shortcuts
Modern Spring development
Enhancing Spring Boot support
CSS preprocessors
Configuring Less and SASS in NetBeans
Configuring Less and Sass on a project basis
Creating CSS rules
Adding JavaScript to a web application
Checking JavaScript files
Summary
9. Creating and Consuming Web Services
Creating web services
Creating a SOAP web service
Creating a SOAP web service from scratch
Creating a SOAP web service from WSDL
Managing SOAP-based web services
Testing web services
Message handlers
Managing web services graphically
Consuming SOAP web services
Creating RESTful web services
The Simple Root Resource option
The Container-Item option
The Client-Controlled Container-Item option
Summary
10. Extending NetBeans
Creating NetBeans plugins
NetBeans rich client platform applications
Creating a NetBeans RCP application
Branding the application
Application properties
Creating platform application components
Creating a NetBeans window
Summary
Index

Mastering NetBeans

Mastering NetBeans

Copyright © 2015 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: August 2015

Production reference: 1250815

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78528-264-5

www.packtpub.com

Credits

Author

David Salter

Reviewers

Michel Graciano

Halil Karaköse

Mario Pérez Madueño

Commissioning Editor

Nadeem Bagban

Acquisition Editor

Larissa Pinto

Content Development Editor

Anand Singh

Technical Editor

Ankita Thakur

Copy Editor

Swati Priya

Project Coordinator

Vijay Kushlani

Proofreader

Safis Editing

Indexer

Monica Ajmera Mehta

Production Coordinator

Arvindkumar Gupta

Cover Work

Arvindkumar Gupta

About the Author

David Salter is an enterprise software developer and architect who has been developing software professionally since 1991. His relationship with Java goes right back to the beginning, when he used Java 1.0 to write desktop applications and applets for interactive websites. He has been developing enterprise Java applications using both Java EE (and J2EE) and open source solutions since 2001. He has also written NetBeans IDE 8 Cookbook and Seam 2.x Web Development and coauthored Building SOA-Based Composite Applications Using NetBeans IDE 6, all by Packt Publishing.

First and foremost, I would like to thank my wife and family for putting up with my many hours at the computer while writing this book. Special thanks and love to my wife for all her encouragement and support.

I'd also like to say thanks to all the people at Packt Publishing for helping me with this book. Thank you, Larissa, for your encouragement from the beginning. I would also like to thank Anand and Ankita for their hard work in helping me complete this book.

Finally, thanks to everyone who has worked on NetBeans, making it the product it is today. Without you all, this book would not exist.

About the Reviewers

Michel Graciano is highly familiar with development techniques, such as object- and component-oriented programming, design patterns' applicability, and software analysis. An expert in application development with open source software, he is currently working as an instructor at Código Efetivo, a training company in Brazil.

He is actively involved with open source projects, such as NetBeans, and has delivered talks at JustJava, The Developer's Conference, and JavaOne conferences.

His longtime contributions to NetBeans started with the Portuguese translation project and continued through his participation in the NetFIX and NetCAT programs, leading to him becoming a NetBeans Dream Team member.

I would like to thank my wife for all her encouragement and support, in this and the other projects I get involved in.

Halil Karaköse is a freelance software architect who graduated from Işik University Computer Engineering Department in 2005.

He worked in the telecommunications industry as a software developer and software architect for 10 years, including companies such as Turkcell and Ericsson. In 2014, he quit Ericsson to establish his own software consultancy company, kodfarki.com.

He has keen interest in Java tools, which speed up development, such as NetBeans and Intellij IDEA. He loves mouseless driven development.

Mario Pérez Madueño graduated in computer engineering from the Open University of Catalonia (UOC), Spain, in 2010. He is an early adopter of Java tech and advocates agile development methodologies. He has been a member of the NetBeans Community Acceptance Testing (NetCAT) program for many years. He has also contributed as a technical reviewer to Building SOA-Based Composite Applications Using NetBeans IDE 6 and Java EE 7 Development with NetBeans 8, both by Packt Publishing.

I would like to thank my wife, María, for her unconditional help and support in all the projects I get involved in. I would also like to thank Martín and Matías for giving me the strength to go ahead.

www.PacktPub.com

Support files, eBooks, discount offers, and more

For support files and downloads related to your book, please visit www.PacktPub.com.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

https://www2.packtpub.com/books/subscription/packtlib

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

Why subscribe?

Fully searchable across every book published by PacktCopy and paste, print, and bookmark contentOn demand and accessible via a web browser

Free access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

Preface

NetBeans is the only IDE that can be downloaded with Java itself. It provides developers with many cutting-edge features that are not available with all the other IDEs.

This book will teach you how to master the NetBeans IDE. You will learn how to utilize and master the NetBeans IDE to become a proficient developer.

This book is packed with many hints, tips, and time-saving techniques. Reading this book will teach you about the features provided by NetBeans that newcomers to the IDE are not aware of and experienced programmers make extensive use of on a day-to-day basis.

What this book covers

Chapter 1, Getting Started with NetBeans, describes the different versions of NetBeans that are available to download and shows you how to install NetBeans from an installable package or from the source code.

Chapter 2, Editing Files and Projects, teaches you about the many different facilities available while editing files. You will learn about macros, project groups, the NetBeans windowing system, and much more.

Chapter 3, The NetBeans Developer's Life Cycle, explains how NetBeans helps with the tasks that every developer does on a daily basis—running, debugging, testing, and profiling applications.

Chapter 4, Managing Services, shows you how NetBeans manages external services such as Maven repositories, PaaS, and continuous integration systems.

Chapter 5, Database Persistence, describes the features that NetBeans provides to help write database applications, from both a code-first and data-first perspective.

Chapter 6, Desktop Development, describes the excellent features provided by NetBeans for developing desktop Swing applications.

Chapter 7, Creating the Business Layer, teaches you the tools provided to help developers write the business layers of applications, describing subjects such as EJBs and bean validation.

Chapter 8, Creating the Web Tier, explains the different features available for Java web developers, including details of creating Spring web applications and using CSS preprocessors.

Chapter 9, Creating and Consuming Web Services, explains how NetBeans makes it straightforward to create and consume both RESTful and SOAP-based web services.

Chapter 10, Extending NetBeans, describes how to create NetBeans plugins for those situations where you need to customize the IDE along with the details of how to start using NetBeans as the platform for desktop applications.

What you need for this book

To use this book, you need to download and install the NetBeans IDE on either Windows, Mac OS X, or Linux.

You also need to have a modern version of Java (preferably, Java 8). To benefit the most when learning about web services and EJB-related technologies, a Java EE application server is required. The enterprise download bundle of NetBeans is supplied with full support for GlassFish 4 Open Source edition.

Who this book is for

This book is written for Java developers of all the levels who want to gain more knowledge about how their IDE works and learn new techniques to enable them to become more productive when using NetBeans.

A reasonable level of Java and Java EE knowledge is assumed.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

To send us general feedback, simply e-mail <[email protected]>, and mention the book's title in the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from: https://www.packtpub.com/sites/default/files/downloads/2645OS_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Getting Started with NetBeans

NetBeans IDE 8 is the official IDE for Java 8, and the only IDE that can be downloaded with official distributions of Java 8.

The latest version, NetBeans IDE 8.0.2, provides tools to allow developers to create desktop, mobile, and web applications using all of the latest Java specifications such as Java SE 8, Java ME 8, and Java EE 7.

This chapter will cover the following topics:

Choosing a download bundle of NetBeansDownloading and installing NetBeansUpdating NetBeans to the latest versionDownloading NetBeans source code from MercurialBuilding NetBeansNetBeans configuration

Choosing a download bundle of NetBeans

There are three different installation bundles of NetBeans (which can be downloaded from the NetBeans site) that are relevant to Java developers:

Java SEJava EEAll

In addition to these three bundles, C/C++ and HTML5 & PHP bundles are also available for download. These bundles are not targeted at Java developers though, so they will not be discussed further in this book.

The Java SE bundle provides the standard NetBeans Platform SDK along with support for Java SE and Java FX developers.

The Java EE bundle contains everything that the SE bundle includes, but adds support for Java EE and HTML5 developers. GlassFish Server Open Source Edition 4.1 and Apache Tomcat 8.0.15 are also included with the Java EE bundle.

The All bundle contains everything that the EE bundle includes, but adds support for C/C++, Groovy, and PHP developers.

Downloading and installing NetBeans

Downloading an installation of NetBeans (Java SE, Java EE, or All) is achieved by selecting the bundle to download and then clicking on the Download button for that bundle, as shown in the preceding screenshot.

All of the examples and screenshots in this book have been created with the Java EE bundle of NetBeans. It is recommended that you use the Java EE download bundle of NetBeans to adhere as closely as possible to the examples in this book.

Note

To install any version of NetBeans 8, the Java JDK Version 7 Update 10 or later, or Java JDK 8 or later, is required. These can be downloaded, if not already installed on your target system, from http://www.oracle.com/technetwork/java/javase/downloads.

Having downloaded the appropriate NetBeans bundle installer for your operating system, you can install NetBeans on your development system. The installation procedure differs slightly for the three main operating systems NetBeans is available for.

For Windows, simply launch the NetBeans installer by double-clicking on the file, netbeans-<xxx>-windows.exe (the exact filename differs depending upon the version and bundle downloaded).

For Mac OS X, double-click on the downloaded file, netbeans-<xxx>-macosx.dmg, to mount the installation device. From there, double-click on the included NetBeans xxx.mpkg file to start the installation (the exact names of the .dmg and .mpkg files vary, depending upon the version and bundle downloaded).

For Linux, NetBeans is installed via a command-line script, so first we must change the permissions of the downloaded file to be executable. From a terminal window, execute the following command:

chmod +x netbeans-<xxx>-linux.sh

Tip

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you. You can also download the code samples from https://github.com/doobrie/masteringnb.

To continue with the installation on Linux, we must now execute the downloaded installer. From a terminal window, execute the following command:

./netbeans-xxx-linux.sh

Tip

The installation of the JDK can sometimes be complex on some Linux distributions. Fortunately, NetBeans can be easily executed with an unpacked JDK. If installation of the JDK is complex, simply unpack the JDK files into a <jdk_folder> folder and then execute the installer with the –javahome argument passing in the JDK folder, for example, /netbeans-xxx-linux.sh –javahome <jdk_folder>.

On all of the major operating systems (Windows, Mac OS X, and Linux), the procedure for installing NetBeans is now very similar. After launching the setup procedure, the installer takes you through the several steps in a wizard style to install NetBeans.

Having agreed to the NetBeans license and selected a folder for installation, the installer displays the Installation Type window:

From here, we can customize NetBeans by clicking on the Customize button.

Note

On Windows and Linux, the preceding screenshot will differ slightly, showing the different application servers that can be installed with NetBeans.

The next screenshot shows the customization options for the Java EE bundle. The options may differ depending upon which bundle you choose to download. For the Java EE bundle, different base components of the NetBeans Platform can be installed, namely Base IDE, Java SE, HTML5, and Java EE.

The Java EE bundle (and also the All bundle) gives the option of installing GlassFish Open Source Edition and Tomcat 8. If either GlassFish or Tomcat is chosen for installation, NetBeans will automatically configure them as servers within the IDE.

Installing other versions of NetBeans

Usually, installing the latest released version of NetBeans is the best course of action. With NetBeans, however, it is possible to download and install the previous versions or even daily builds.

Tip

Be careful with daily builds; they have not been through the rigorous testing procedure that the full release builds had, and may contain bugs!

To download the previous released versions of NetBeans, browse to the NetBeans download page at http://www.netbeans.org/downloads and click on the Archive link in the top-right corner of the page, as shown in the following screenshot:

Tip

For easy access, the previous version of NetBeans is available for downloading by clicking on the appropriate link at the top of the page (version 8.0.1 in the preceding screenshot) rather than clicking on the Archive link and manually selecting a version to install.

From the resultant page, select the previous release you wish to download (for example, NetBeans 7.3) and then click on the Continue button. From here, you can choose whether to download the Java SE, Java EE, or All distributions of NetBeans. The following screenshot shows the previous versions of NetBeans that are currently available for download:

To download the latest daily build of NetBeans, simply click on the Development link in the top-right corner of the NetBeans download page. Again, from the resulting page, select the download bundle (Java SE, Java EE, or All) you require and follow the standard NetBeans installation procedure for your operating system, as outlined previously.

NetBeans user directory

When installing NetBeans, a special directory is created on your computer that stores all the user configuration data for NetBeans; this folder is referred to as a userdir or user directory. This folder contains information on what plugins you have activated in NetBeans, what editor settings you've configured, and much more data. In fact, everything that makes your instance of NetBeans unique to you is stored in this folder.

On Mac OS X, the user directory is located at ~/Library/Application Support/NetBeans.

On Windows, it is located at c:\Users\<user>\AppData\Roaming\NetBeans.

On Linux, the user directory is located at ~/.netbeans.

In the user directory are the separate directories for each different version of NetBeans that you have installed. With this technique, it is therefore possible to have different configurations for different versions of NetBeans that are installed.

In addition to a user directory, NetBeans also makes use of a hidden cache directory, often referred to as a cachedir. The cache directory contains large amount of cache data and thus, it can become a large directory. Due to the information that's written into the cache directory, it must be stored in a different location to the user directory. The contents of the cache directory can be deleted without any settings being lost; it will be recreated the next time NetBeans is executed.

On Mac OS X, the cache directory is located at ~/Library/Caches/NetBeans.

On Windows, the cache directory is located at c:\Users\<user>\AppData\Local\NetBeans\Cache.

On Linux, the cache directory is located at ~/.cache/netbeans.

An easy way to find out the location of the user and cache directories is to display the NetBeans About dialog. In this dialog, the location of these directories is given along with the information about the version of NetBeans and Java that are in use:

Updating NetBeans to the latest version

When new versions of NetBeans are released, one simple way to upgrade to the latest version is to download the new version and install it, as shown previously.

When you install NetBeans this way and already have an installation of NetBeans on your computer, NetBeans will ask whether you wish to use the settings from the previous version:

Selecting Yes to this option will import all of the user directory settings from the previous version of NetBeans into the newly installed version. Selecting No will start NetBeans with a clean and empty user directory.

Tip

After installing a new version of NetBeans, it's always a good idea to check whether there are any updates to plugins by going to the plugin manager and selecting Check for Updates.

Obtaining the NetBeans source code

The source code for NetBeans itself is available under the Common Development and Distribution License (CDDL) v1.0 and GNU General Public License (GPL) v2.

It's possible to obtain the source for NetBeans either as a .zip file, containing the entire source for a specific release, by cloning the code from the NetBeans Mercurial repository or by viewing the files from within a browser.

Downloading a zipped archive of the NetBeans source code

If you just want to look at the NetBeans source code and aren't interested in making changes, you can download the source as a .zip archive from the relevant download page for any release. At the bottom of each download page, there is a link to download the source in the ZIP file format, as shown in the following screenshot:

Cloning the NetBeans source code from Mercurial

The alternative to downloading a ZIP archive of the NetBeans source code is to clone the code from the NetBeans Mercurial repository. To perform this operation, you must have the Mercurial client installed on your computer. It can be downloaded for Windows and Mac OS X. For Linux and Mac OS X, it can be installed via the operating system's appropriate package manager, for example, apt-get on Ubuntu or yum install on Fedora. The Mercurial site at http://mercurial.selenic.com provides all the details on how to install Mercurial.

The NetBeans source code can be cloned from Mercurial from either the command line or from within NetBeans. Let's first look at how to achieve this using the command line.

Having installed Mercurial, we are in a good position to clone the NetBeans source code using the hg clone operation.

The NetBeans source code is stored within several branches and tags in the Mercurial repository. The main development for the next version of NetBeans is performed within the main-silver branch. This branch contains the latest development that has been picked up by the latest automatic stable build of NetBeans.

To check out this branch, execute the following command from within a terminal or command prompt:

hg clone http://hg.netbeans.org/main-silver

If this is your first check out of a branch, Mercurial may take a long time to clone the repository. Depending on your computer and network connection, this may take several hours.

Due to the way Mercurial works, hidden files are created on the local filesystem during the first phase of a Mercurial clone operation. No console output is provided during the checkout phase either, so it may appear that the clone operation is not working correctly as there is no visible feedback that the sources are being cloned.

It's possible to tell Mercurial to output status information so that you can see that all is working correctly. This can be especially useful on the first clone of a branch, which can be a lengthy operation. To clone a branch and get status updates output to the console, we must add the --debug parameter onto the clone operation:

hg --debug clone http://hg.netbeans.org/main-silver/

After cloning the NetBeans source files from the Mercurial repository, we have many subdirectories within the main-silver directory, as shown in the following screenshot:

Cloning specific versions of NetBeans

In the previous section, we showed how to clone the main-silver branch from the NetBeans Mercurial repository. What if we don't want the latest cutting edge development, but want to look at the source code for a specific version of NetBeans?

Fortunately, each release of NetBeans has the source code tagged in the Mercurial repository, so it's possible to check out any older release going back to December 1999 (this is the first tagged release within Mercurial).

The complete list of tagged releases is available at http://hg.netbeans.org/releases/tags, as shown in the following screenshot:

To view any of these tagged releases, simply check out the releases branch and then change to the specified folder for the requested release.

Cloning the NetBeans source code from within NetBeans

To enable us to use Mercurial from within NetBeans, we must first ensure that NetBeans is configured with the location of the Mercurial executable—hg.exe on Windows and hg on Mac OS X and Linux.

To configure Mercurial within NetBeans, perform the following steps:

Open the NetBeans Options dialog. On Windows and Linux, this is achieved by selecting Tools and then Options from the main menu. On Mac OS X, clicking on NetBeans and then Preferences from the application menu opens the Options dialog.In the Options dialog, click on the Team option and then choose the Versioning tab.On the Versioning tab, ensure that the Mercurial Executable Path field is set as appropriate for your operating system. In the preceding screenshot, you can see that it is set to /usr/local/bin, which is the folder that contains the hg executable on my computer.

Once we've configured the Mercurial support within NetBeans, we can clone the source code repository by performing the following steps:

Open the Clone External Repository wizard by clicking on Team and then Mercurial and eventually, Clone Other… from the application menu.Enter the repository URL as http://hg.netbeans.org/main-silver.Continue on through the wizard until the Destination Directory stage is displayed. On this page, enter the parent directory into which the NetBeans source code will be cloned and ensure that the Scan for NetBeans Projects after Clone option is checked. With this option checked, NetBeans will automatically open the cloned project after the repository is cloned.Click on the Finish button to commence the cloning process.

Tip

Cloning the NetBeans source code in this way via NetBeans does not provide any visual feedback on the progress of the cloning operation. If you wish to see visual feedback so that you know something is happening, consider cloning the repository via the command line, as described earlier.

Browsing the NetBeans source code online

The NetBeans source code is available to browse online at http://hg.netbeans.org/main/file. Viewing the source code this way can be very useful for the casual observer who wants to see how something is done within the NetBeans source code, but does not want to download the entire source code to their computer.

The following screenshot shows the top level of the NetBeans source code in a browser window:

Building NetBeans

Once we've downloaded the source code for NetBeans, we can build it either using the command line or via NetBeans.

To build the NetBeans IDE from the source code, we need to have the following software installed first:

JDK 7Apache Ant

Tip

NetBeans can be built with JDK 8, but additional steps are required for this; we'll see what these are shortly!

Building NetBeans via the command line

To build NetBeans via the command line, open up a terminal or command prompt and change the directory to the directory containing the source code. Executing the ant command will build the source code, downloading any external dependencies that are required:

[david:~/Develop/NetBeans/main-silver]$ ant

If you are running JDK 8 instead of 7, you will be presented with an error when attempting to build the source code stating that builds are forbidden when using JDK 8. This error is presented so as not to introduce any Java 8 features into the source code.

If you wish to use JDK 8 to build the code, you can set the permit.jdk8.builds property to true:

[david:~/Develop/NetBeans/main-silver]$ ant –Dpermit.jdk8.builds=true

Alternatively, if you have both JDK 7 and 8 installed, you can set the nbjdk.home property to point to a valid JDK 7 installation and the build will then complete using the specified JDK 7 instead of JDK 8.

Once you have successfully build NetBeans, you can execute the freshly built instance by executing the ant tryme task:

[david:~/Develop/NetBeans/main-silver]$ ant tryme

This will execute the instance of NetBeans that you have just built using <build-location>/nbbuild/testuserdir as the user directory. The actual instance of NetBeans is stored within the <build-location>/nbbuild/netbeans folder.

Alternatively, you can also start the freshly-built instance of NetBeans by executing the netbeans or netbeans.exe commands from within the <build-location>/nbbuild/netbeans/bin directory, either from the command line of Windows / Linux explorer or Mac OSX Finder.

Building NetBeans from within NetBeans

Now that we've seen how to build NetBeans via the command line, let's see how we can build it from within NetBeans itself.

If you cloned the NetBeans source code via the team support in NetBeans, then the NetBeans Build System project will already be opened within NetBeans, ready for building, as shown in the following screenshot:

If you cloned NetBeans via the command line, you will need to open the NetBeans Build System project located within the main-silver/nbbuild directory.

After opening the project, you will see that there are error badges shown against the Ant Tasks and Tests for Ant Tasks project nodes within the Projects window. These errors simply indicate that artifacts needed for the build haven't been downloaded yet; the build process will download the necessary files, and once built, these error badges will no longer appear.

To start building NetBeans, we must first build the necessary Ant tasks that the full build process relies on. To perform this, right-click on the NetBeans Build System project and select the Build option:

Once the build system is completed with no errors (you will see several warnings displayed during the build process, but these can be safely ignored), you can build NetBeans by right-clicking on the NetBeans Build System project and selecting the Build IDE (No ZIP File) option:

If you are using JDK 7, you will see that NetBeans is built correctly after a few minutes of activity.

If you are using JDK 8, you will see a failure message in the NetBeans output window, indicating that the project cannot be built using JDK 8, as shown in the following screenshot:

Since NetBeans provides its own installation of Ant to build projects, if we wish to use JDK 8 to build NetBeans, we must configure the permit.jdk8.builds property before attempting to build.

To configure the Ant properties from within NetBeans, perform the following steps:

Open the NetBeans Options dialog. On Windows and Linux, this is achieved by selecting Tools and then Options from the main menu. On Mac OS X, clicking on NetBeans and then Preferences from the application menu opens the Options dialog.In the Options dialog, click on the Java option and then choose the Ant tab.Within the Ant tab, append the permit.jdk8.builds=true line into the Properties edit box:Click on the OK button to save the configuration changes.

Now that we've configured the permit.jdk8.builds property for the internal instance of Ant, we can build the project successfully using JDK 8. This is achieved by right-clicking on the NetBeans Build System project within the Projects window and selecting the Build IDE (No ZIP File) option.

NetBeans configuration

In the previous sections of this chapter, we saw how to choose an installation of NetBeans and install it. We also saw how to download and build NetBeans from its Java source code.

Let's now take a look at the different options that are used to start NetBeans and see how these can be configured.

The configuration options used to start NetBeans are defined as command-line arguments in the netbeans.conf file supplied with a NetBeans distribution.

On Windows and Linux, this file is located within the NetBeans installation directory at <NetBeans Install Dir>/etc/netbeans.conf.

On Mac OS X, this file is hidden due to the way Mac OS X packages are deployed. To view and edit the netbeans.conf file on OS X, right-click on the NetBeans.app executable file and select the Show Package Contents menu option:

The contents of the NetBeans.app package will then be displayed. The netbeans.conf file is located at Contents/Resources.NetBeans/etc/netbeans.conf within the package contents.

This configuration is a simple text file and can be opened with any text editor. In the file, we can see several configuration properties that can be modified to suit your requirements. Let's go through these now and see what options are available.

User and cache directories

Earlier in this chapter, we discussed the NetBeans user and cache directories and what information is stored within them. If you wish to change the user directory for a specific instance of NetBeans (for example, you may want to use a completely fresh user directory or a user directory from a previous installation of NetBeans), this can be achieved by specifying the netbeans_default_userdir parameter. Similarly, the cache directory can be changed by specifying the netbeans_default_cachedir parameter:

netbeans_default_userdir="${DEFAULT_USERDIR_ROOT}/8.0.2"netbeans_default_cachedir="${DEFAULT_CACHEDIR_ROOT}/8.0.2"

Tip

Unless you have a specific reason, you're probably not going to need to change the user and cache directories for NetBeans.

NetBeans default options

The NetBeans default startup options are probably the most likely of the command-line arguments that you'll need to change for NetBeans. These options are specified by the netbeans_default_options parameter: