Getting Started with NetBeans

Exclusive offer: get 50% off this eBook here
Java EE 6 Development with NetBeans 7

Java EE 6 Development with NetBeans 7 — Save 50%

Develop professional enterprise Java EE applications quickly and easily with this popular IDE

$29.99    $15.00
by David R. Heffelfinger | August 2011 | Java Open Source

NetBeans is an Integrated Development Environment (IDE) and platform. Although initially the NetBeans IDE could only be used to develop Java applications, as of version 6 NetBeans supports several programming languages, either by built-in support or by installing additional plugins. Programing languages natively supported by NetBeans include Java, JavaFX, C, C++ and PHP. Groovy, Scala, Ruby and others are supported via additional plugins.

In this article by David R. Heffelfinger, author of Java EE 6 Development with NetBeans 7, we will cover how to get started with NetBeans; topics covered in this article include:

  • Introduction
  • Obtaining NetBeans
  • Installing NetBeans
  • Starting NetBeans for the first time
  • Configuring NetBeans for Java EE development

 

Java EE 6 Development with NetBeans 7

Java EE 6 Development with NetBeans 7

Develop professional enterprise Java EE applications quickly and easily with this popular IDE

        Read more about this book      

(For more resources on NetBeans, see here.)

 

In addition to being an IDE, NetBeans is also a platform. Developers can use NetBeans' APIs to create both NetBeans plugins and standalone applications.

For a brief history of Netbeans, see http://netbeans.org/about/history.html.

Although the NetBeans IDE supports several programming languages, because of its roots as a Java only IDE it is a lot more popular with this language. As a Java IDE, NetBeans has built-in support for Java SE (Standard Edition) applications, which typically run in the user's desktop or notebook computer; Java ME (Micro Edition), which typically runs in small devices such as cell phones or PDAs; and for Java EE (Enterprise Edition) applications, which typically run on "big iron" servers and can support thousands of concurrent users.

 

Obtaining NetBeans

NetBeans can be obtained by downloading it from http://www.netbeans.org.

Java EE 6 Development with NetBeans 7

To download NetBeans, we need to click on the button labeled Download Free NetBeans IDE 7.0 (the exact name of the button may vary depending on the current version of NetBeans). Clicking on this button will take us to a page displaying all of NetBeans download bundles.

Java EE 6 Development with NetBeans 7

NetBeans download includes different NetBeans bundles that provide different levels of functionality. The following table summarizes the different available NetBeans bundles and describes the functionality they provide:

NetBeans bundle Description
Java SE Allows development of Java desktop applications.
Java EE Allows development of Java Standard Edition (typically desktop applications), and Java Enterprise Edition (enterprise application running on "big iron" servers) applications.
C/C++ Allows development of applications written in the C or C++ languages.
PHP Allows development of web applications using the popular open source PHP programming language.
All Includes functionality of all NetBeans bundles.

To follow the examples, either the Java EE or the All bundle is needed.

The screenshots were taken with the Java EE bundle. NetBeans may look slightly different if the All Pack is used, particularly, some additional menu items may be seen.

The following platforms are officially supported:

  • Windows 7/Vista/XP/2000
  • Linux x86
  • Linux x64
  • Solaris x86
  • Solaris x64
  • Mac OS X

Additionally, NetBeans can be executed in any platform containing Java 6 or newer. To download a version of NetBeans to be executed in one of these platforms, an OS independent version of NetBeans is available for download.

Although the OS independent version of NetBeans can be executed in all of the supported platforms, it is recommended to obtain the platform-specific version of NetBeans for your platform.

The NetBeans download page should detect the operating system being used to access it, and the appropriate platform should be selected by default. If this is not the case, or if you are downloading NetBeans with the intention of installing it in another workstation on another platform, the correct platform can be selected from the drop down labeled, appropriately enough, Platform.

Once the correct platform has been selected, we need to click on the appropriate Download button for the NetBeans bundle we wish to install. For Java EE development, we need either the Java EE or the All bundle. NetBeans will then be downloaded to a directory of our choice.

Java EE applications need to be deployed to an application server. Several application servers exist in the market, both the Java EE and the All NetBeans bundles come with GlassFish and Tomcat bundled. Tomcat is a popular open source servlet container, it can be used to deploy applications using the Servlets, JSP and JSF, however it does not support other Java EE technologies such as EJBs or JPA. GlassFish is a 100 percent Java EE-compliant application server. We will be using the bundled GlassFish application server to deploy and execute our examples.

 

Installing NetBeans

NetBeans requires a Java Development Kit (JDK) version 6.0 or newer to be available before it can be installed.

NetBeans installation varies slightly between the supported platforms. In the following few sections we explain how to install NetBeans on each supported platform.

Microsoft Windows

For Microsoft Windows platforms, NetBeans is downloaded as an executable file named something like netbeans-7.0-ml-java-windows.exe, (exact name depends on the version of NetBeans and the NetBeans bundle that was selected for download). To install NetBeans on Windows platforms, simply navigate to the folder where NetBeans was downloaded and double-click on the executable file.

Mac OS X

For Mac OS X, the downloaded file is called something like netbeans-7.0-ml-javamacosx.dmg (exact name depends on the NetBeans version and the NetBeans bundle that was selected for download). In order to install NetBeans, navigate to the location where the file was downloaded and double-click on it.

The Mac OS X installer contains four packages, NetBeans, GlassFish, Tomcat, and OpenESB, these four packages need to be installed individually, They can be installed by simply double-clicking on each one of them. Please note that GlassFish must be installed before OpenESB.

Linux and Solaris

For Linux and Solaris, NetBeans is downloaded in the form of a shell script. The name of the file will be similar to netbeans-7.0-ml-java-linux.sh, netbeans-7.0-mljava-solaris-x86.sh, or netbeans-7.0-ml-java-solaris-sparc.sh, depending on the version of NetBeans, the selected platform and the selected NetBeans bundle.

Before NetBeans can be installed in these platforms, the downloaded file needs to be made executable. This can be done in the command line by navigating to the directory where the NetBeans installer was downloaded and executing the following command:

chmod +x ./filename.sh

Substitute filename.sh with the appropriate file name for the platform and the NetBeans bundle.

Once the file is executable it can be installed from the command line:

./filename.sh

Again substitute filename.sh with the appropriate file name for the platform and the NetBeans bundle.

Other platforms

For other platforms, NetBeans can be downloaded as a platform-independent zip file. The name of the zip file will be something like netbeans-7.0-201007282301-mljava.zip (exact file name may vary, depending on the exact version of NetBeans downloaded and the NetBeans bundle that was selected).

To install NetBeans on one of these platforms, simply extract the zip file to any suitable directory.

 

Java EE 6 Development with NetBeans 7 Develop professional enterprise Java EE applications quickly and easily with this popular IDE
Published: June 2011
eBook Price: $29.99
Book Price: $49.99
See more
Select your format and quantity:

 

        Read more about this book      

(For more resources on NetBeans, see here.)

 

Installation procedure

Even though the way to execute the installer varies slightly between platforms, the installer behaves in a similar way between most of them.

One exception is the Mac OS X installer, under Mac OS X, each individual component (NetBeans, GlassFish, Tomcat, and OpenESB) comes with its own installer and must be installed individually. GlassFish must be installed before OpenESB.
Another exception is the platform-independent zip file. In this case there is essentially no installer, installing this version of NetBeans consists of extracting the zip file to any suitable directory.

After executing the NetBeans installation file for our platform, we should see a window similar to the one illustrated in the following screenshot:

Java EE 6 Development with NetBeans 7

The packs shown may vary depending on the NetBeans bundle that was downloaded; the above screen shot is for the "Java EE" bundle.

At this point we should click on the button labeled Next> to continue the installation.

Java EE 6 Development with NetBeans 7

NetBeans is dual licensed, licenses for NetBeans include the GNU Public License (GPL) version 2 with CLASSPATH exception, and the Common Development and Distribution License (CDDL). Both of these licenses are approved by the Open Source Initiative (OSI).

To continue installing NetBeans, click on the checkbox labeled I accept the terms in the license agreement and click on the button labeled Next>.

Java EE 6 Development with NetBeans 7

We need to either accept the terms of the JUnit license at this point or choose not to install JUnit

At this point the installer will prompt us for a NetBeans installation directory, and for a JDK to use with NetBeans. We can either select new values for these or take the provided defaults.

Once we have selected the appropriate installation directory and JDK, we need to click on the button labeled Next> to continue the installation.

NetBeans uses the JAVA_HOME environment variable to populate the JDK directory location.

Java EE 6 Development with NetBeans 7

The installer will now prompt us for an installation directory for the GlassFish application server; we can either enter a directory or take the default.

Java EE 6 Development with NetBeans 7

In the next step in the wizard, the installer will prompt us for an installation directory for Tomcat, a very popular servlet container, which is bundled with NetBeans.

Java EE 6 Development with NetBeans 7

At this point the installer will display a summary of our choices. After reviewing the summary, we need to click on the button labeled Install to begin the installation.

Java EE 6 Development with NetBeans 7

At this point the installation will begin. The installer displays a progress bar indicating how far along in the installation it is.

Java EE 6 Development with NetBeans 7

After NetBeans and all related components have been installed, the installer indicates a successful installation, giving us the option to contribute anonymous usage data. After making our selection we can simply click on the Finish button to exit the installer.

On most platforms, the installer places a NetBeans icon on the desktop, the icon should look like the following image:

Java EE 6 Development with NetBeans 7

 

Starting NetBeans for the first time

We can start NetBeans by double-clicking on its icon, we should see the NetBeans splash screen while it is starting up.

Java EE 6 Development with NetBeans 7

Once NetBeans starts, we should see a page with links to demos, tutorials, sample projects, etc.

Java EE 6 Development with NetBeans 7

NetBeans defaults to showing this start page every time it is started, if we don't wish for this page to be displayed automatically every time NetBeans is started, we can disable this behavior by un-checking the checkbox labeled Show on Startup at the bottom of the page. We can always get the start page back by going to Help | Start Page.

 

Java EE 6 Development with NetBeans 7 Develop professional enterprise Java EE applications quickly and easily with this popular IDE
Published: June 2011
eBook Price: $29.99
Book Price: $49.99
See more
Select your format and quantity:

 

        Read more about this book      

(For more resources on NetBeans, see here.)

 

Configuring NetBeans for Java EE development

NetBeans comes preconfigured with the GlassFish 3 application server, and with the JavaDB RDBMS. If we wish to use the included GlassFish 3 and JavaDB RDBMS, there is nothing we need to do to configure NetBeans.

We can, however, integrate NetBeans with other Java EE application servers such as JBoss, Weblogic, or WebSphere and with other Relational Database Systems such as MySQL, PostgreSQL, Oracle, or any RDBMS supported by JDBC, which pretty much means any RDBMS.

Integrating NetBeans with a third party application server

Integrating NetBeans with an application server is very simple, to do so, we need to follow the following steps:

In this section we will illustrate how to integrate NetBeans with JBoss, the procedure is very similar for other application servers or servlet containers.

  1. First, we need to click on Window | Services.

    Java EE 6 Development with NetBeans 7

  2. Next, we need to right-click on the node labeled Servers in the tree inside the Services window, and select Add Server... from the resulting pop up menu.

    Java EE 6 Development with NetBeans 7

  3. Then we need to select the server to install from the list in the resulting window, and click on the button labeled Next>.

    Java EE 6 Development with NetBeans 7

  4. We then need to enter a location in the file system where the application server is installed and click Next>.

    Java EE 6 Development with NetBeans 7

  5. Finally, we need to select a domain, host, and port for our application server, and then click on the Finish button.

    Java EE 6 Development with NetBeans 7

The Services window should now display our newly added application server.

Java EE 6 Development with NetBeans 7

That's it! We have successfully integrated NetBeans with a third party application server.

 

Integrating NetBeans with a third party RDBMS

NetBeans comes with built-in integration with the JavaDB RDBMS system. Additionally, it comes with JDBC drivers for other RDBMS systems such as MySQL and PostgreSQL. It also comes with the JDBC-ODBC bridge driver to connect to RDBMS systems that don't natively support JDBC or for which a JDBC driver is not readily available.

Although using the JDBC-ODBC bridge allows us to connect to most RDBMS systems without having to obtain a JDBC driver, it is usually a better idea to obtain a JDBC driver for our RDBMS. The JDBC-ODBC bridge does not offer the best performance and there are JDBC drivers available for the vast majority of RDBMS systems.

In this section, we will create a connection to HSQLDB, an open source RDBMS written in Java. The idea is to illustrate how to integrate NetBeans with a third party RDBMS, the procedure is very similar for other RDBMS systems such as Oracle, Sybase, SQL Server, and so on.

Adding a JDBC driver to NetBeans

Before we can connect to a third party RDBMS, we need to add its JDBC driver to NetBeans. To add the JDBC driver, we need to right-click on the Drivers node under the Databases node in the Services tab.

Java EE 6 Development with NetBeans 7

We then need to select a JAR file containing the JDBC driver for our RDBMS, NetBeans guesses the name of the driver class containing the JDBC driver. If more than one driver class is found in the JAR file, the correct one can be selected from the drop down menu labeled Driver Class. We need to click on the OK button to add the driver to NetBeans.

Java EE 6 Development with NetBeans 7

Once we have followed the above procedure, our new JDBC driver is displayed in the list of registered drivers.

Java EE 6 Development with NetBeans 7

Connecting to a third party RDBMS

Once we have added the JDBC driver for our RDBMS to NetBeans, we are ready to connect to the third party RDBMS.

To connect to our third party RDBMS, we need to right click on its driver on the Services tab, then click on Connect Using... on the resulting pop up menu.

Java EE 6 Development with NetBeans 7

Then we need to enter the JDBC URL, username, and password for our database.

Java EE 6 Development with NetBeans 7

After clicking on the OK button, NetBeans may ask us to select a database schema.

Java EE 6 Development with NetBeans 7

After selecting the schema and clicking on the OK button, our database is shown in the list of databases in the Services window. We can connect to it by right-clicking on it, selecting Connect from the resulting pop up, then entering our username and password for the database (we can choose not to allow NetBeans to "remember" the password when we add the database).

Java EE 6 Development with NetBeans 7

We have now successfully connected NetBeans to a third party RDBMS.

Summary

In this article, we provided a brief history of how Java EE came into existence. We also explained how to obtain and install NetBeans for the different platforms it supports. Additionally, we explained how to set up NetBeans with third party Java EE application servers and with third party Relational Database Systems, including how to register a JDBC driver for the RDBMS in question.


Further resources on this subject:


About the Author :


David R. Heffelfinger

David Heffelfinger is the Chief Technology Officer of Ensode Technology, LLC, a software consulting firm based in the greater Washington DC area. He has been architecting, designing and developing software professionally since 1995 and has been using Java as his primary programming language since 1996. He has worked on many large scale projects for several clients including the US Department of Homeland Security, Freddie Mac, Fannie Mae, and the US Department of Defense. He has a Masters degree in Software Engineering from Southern Methodist University. David is editor in chief of Ensode.net (http://www.ensode.net), a website about Java, Linux, and other technology topics.

Books From Packt


NetBeans IDE 7 Cookbook
NetBeans IDE 7 Cookbook

Java EE 6 with GlassFish 3 Application Server
Java EE 6 with GlassFish 3 Application Server

Learning Ext JS 3.2
Learning Ext JS 3.2

Django JavaScript Integration: AJAX and jQuery
Django JavaScript Integration: AJAX and jQuery

Apache Wicket Cookbook
Apache Wicket Cookbook

BlackBerry Java Application Development
BlackBerry Java Application Development

jQuery 1.4 Reference Guide
jQuery 1.4 Reference Guide

Learning jQuery 1.3
Learning jQuery 1.3


Code Download and Errata
Packt Anytime, Anywhere
Register Books
Print Upgrades
eBook Downloads
Video Support
Contact Us
Awards Voting Nominations Previous Winners
Judges Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software
Resources
Open Source CMS Hall Of Fame CMS Most Promising Open Source Project Open Source E-Commerce Applications Open Source JavaScript Library Open Source Graphics Software