Installing Netbeans
From InstallationWiki
| Official Page |
| Project Documentation |
| Download |
|
In this tutorial, we will cover how to get started with NetBeans, topics covered in this tutorial include:
- Introduction
- Downloading NetBeans
- Installing NetBeans
- Starting NetBeans for the first time
- Configuring NetBeans for Java EE development
- Deploying our first application
- NetBeans tips for effective development
Contents |
[edit] Introduction
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. Programming languages natively supported by NetBeans include Java, C, C++, Ruby, PHP, and Groovy. Developers can use NetBeans' API's to create both NetBeans plugins and standalone applications, taking advantage of NetBeans as a platform.
The NetBeans IDE supports several programming languages, but because of its roots as Java-only IDE, it is a lot more popular with Java language. As a Java IDE, NetBeans has built-in support for Java SE (Standard Edition) applications, which typically run in the user's desktop
Some of the features we will cover include how NetBeans can help us speed up web applications using the Servlet API and JSPs by providing a starting point for these kind of artifacts, and how we can use the NetBeans palette to drag-and-drop code snippets into our JSPs, including HTML and JSP markup. We will also see how NetBeans can help us generate JPA entities from an existing database schema (JPA is the Java Persistence API, the standard Object-Relational mapping tool included with Java EE). We will see how NetBeans allows us to visually create web applications using the JavaServer Faces framework via its visual web development tool.
In addition to web development, we will also see how NetBeans allows us to add business methods to a stateless or stateful session bean in one shot, without having to add the method both to the bean and to its business interface, and how to easily develop web services. We will also cover how to easily write both EJB and web service clients by taking advantage of some very nice NetBeans features.
Before taking advantage of all of the above NetBeans features, we of course need to have NetBeans installed, as covered in the next section.
[edit] Downloading NetBeans
NetBeans can be downloaded from http://www.netbeans.org.
At the time of writing, NetBeans 6.5 is in beta, by publication time it should be the current version. To download NetBeans we need to click on the button labeled Download NetBeans IDE. Clicking on this button will take us to a page displaying all of NetBeans download bundles.
NetBeans download bundles contain different NetBeans Packs that provide different levels of functionality. The following table summarizes the different available NetBeans packs and describes the functionality they provide.
| NetBeans Pack | Description |
|---|---|
| Java | Includes features for development of Java Standard Edition applications, as well as web and Java Enterprise Edition and mobile applications. |
| Ruby | Includes features for development of applications written in the Ruby language. |
| C/C++ | Includes features for development of applications written in the C or C++ languages. |
| PHP | Includes features for development of PHP applications. |
| All | Includes functionality of all NetBeans packs. |
The following platforms are officially supported:
- Windows 2000/XP/Vista
- Linux x86
- Linux x64
- Solaris x86
- Solaris x64
- Mac OS X
Additionally, NetBeans can be used under any platform containing JDK 5.0 or newer. To download a version of NetBeans to be used under one of these platforms, an OS independent version of NetBeans is available for download.
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 pack we wish to install; for Java EE development, we need either the Java or the All Pack. NetBeans will then be downloaded to a directory of our choosing.
[edit] Installing NetBeans
NetBeans installation varies slightly between the supported platforms. In the following few sections we'll look at how to install NetBeans on each supported platform.
[edit] Microsoft Windows
For Microsoft Windows platforms, NetBeans is downloaded as an executable file named something like netbeans-6.5-windows.exe (the exact name depends on the version of NetBeans and the NetBeans pack that was selected for download). To install NetBeans on Windows platforms, simply navigate to the folder where NetBeans was installed and double-click on the executable file that was downloaded.
[edit] Mac OS X
For Mac OS X, the downloaded file is called something like netbeans-6.5-macosx.dmg (the exact name depends on the NetBeans version and the NetBeans pack 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.
[edit] Linux and Solaris
For Linux and Solaris, NetBeans is downloaded in the form of a shell script. The name of the file will be something like netbeans-6.5-linux.sh, netbeans-6.5-solaris-x86.sh, and netbeans-6.5-solaris-sparc.sh, depending on the version of NetBeans, the selected platform, and the selected NetBeans pack.
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 NetBeans pack.
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 NetBeans pack.
[edit] 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-6.5-200811261600.zip (the exact file name may vary, depending on the version of NetBeans downloaded and the NetBeans pack that was selected).
To install NetBeans on one of these platforms, simply extract the zip file to any suitable directory.
[edit] Installation Procedure
Even though the way to execute the installer varies slightly between platforms, the installer behaves in a similar way between all of them.
After executing the NetBeans installation file for our platform, we should see a window similar to the one illustrated in the following screenshot:
The packs shown may vary depending on the NetBeans pack that was downloaded, the previous screen shot is for the All pack.
At this point we should click on the button labeled Next> to continue the installation.
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>.
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.
The installer will now prompt us for an installation directory, JDK and other information for the GlassFish 2 application server, usually the defaults are sensible, but we can change them if we have a reason to.
At this point the installer will prompt us for an installation directory for the GlassFish 3 application server, providing a sensible default.
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.
At this point installation will begin, the installer displays a progress bar indicating how far along in the installation it is.
After NetBeans and all related components have been installed, the installer indicates a successful installation.
On most platforms, the installer places a NetBeans icon on the desktop, the icon should look like the following image:
[edit] 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.
Once NetBeans starts, we should see a page with links to demos, tutorials, sample projects, and so on.
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 unchecking 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.
[edit] Configuring NetBeans for Java EE Development
NetBeans comes pre-configured with the GlassFish 2 application server, and with the JavaDB RDBMS. If we wish to use the embedded GlassFish 2 and JavaDB RDBMS, then there is nothing we need to do to configure NetBeans.
We can, however, integrate NetBeans with other Java EE application servers such as GlassFish 1, Sun Java Application Server, JBoss, Weblogic, or WebSphere. We can also integrate NetBeans with several versions of Tomcat.
[edit] Integrating NetBeans with a Third Party Application Server
Integrating NetBeans with an application server is very simple. To do so, we need to take the following steps:
First, we need to click on the tab labeled Services, it can be found at the top-right of the NetBeans main window.
Next, we need to right-click on the node labeled Servers in the tree inside the Services tab, and select Add Server... from the resulting pop-up menu.
Then we need to select the server to install from the list in the resulting window, and click on the button labeled Next>.
We then need to enter a location in the file system where the application server is installed and click Next>.
Finally, we need to select a Domain, Host, and Port for our application server, then click on the Finish button.
The Services tab should now display our newly added application server.
That's it! We have successfully integrated NetBeans with a third party application server.
[edit] 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, as well as 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 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.
[edit] 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.
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 the OK button to add the driver to NetBeans.
Once we have followed the above procedure, our new JDBC driver is displayed in the list of registered drivers.
[edit] 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.
Then we need to enter the JDBC URL, username, and password for our database.
After clicking the OK button, NetBeans may ask us to select a database schema.
After selecting the schema and clicking the OK button, our database is shown in the list of databases in the Services tab. 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 (if we chose not to allow NetBeans to "remember" the password when we added the database).
We have now successfully connected NetBeans to a third party RDBMS.
[edit] Deploying Our First Application
NetBeans comes pre-configured with a number of sample applications. To make sure everything is configured correctly, we will now deploy one of the sample applications to the integrated GlassFish application server that comes with NetBeans.
To open the sample project, we need to go to File | New Project, then select Samples | Web | Visual JSF from the categories list in the resulting pop-up window. Once we have selected Visual JSF from the categories list, a list of projects is displayed in the Projects list. For this example we need to select the Corporate Travel Center project.
Clicking on the Next> button, we are prompted to enter a Project Name and Project Location. Typically the defaults are sensible.
Once we click the Finish button, our new project is displayed in the Projects tab.
We can compile, package, and deploy our project all in one shot by right-clicking on it and selecting Run from the resulting pop-up menu.
At this point we should see the output of the build script. Also, both the integrated GlassFish application server and the integrated JavaDB RDBMS system should automatically start. The application server and RDBMS will only be started the first time we deploy our project, therefore the delay due to their initialization will not occur in subsequent deployments.
Once the project is deployed we should see NetBean's HTTP monitor. The HTTP monitor is a tool that helps us better develop web applications by providing values of request parameters, request, session and application attributes, request headers, and so on. The HTTP monitor will be discussed in detail in the next tutorial.
As soon as our application was deployed, a new browser should have automatically started, displaying the default page for our new application. We can select the browser that NetBeans will use by going to Tools | Options, then selecting the appropriate browser from the Web Browser drop-down in the General tab.
The sample web application we just deployed is a Visual JSF application. The application uses a JDBC connection to the sample travel database included with NetBeans. The application uses the Woodstock JSF components that are bundled with NetBeans, and interacts with data stored in the sample travel database included with NetBeans.
If our browser is displaying a page similar to the one above, then we can be certain that NetBeans, GlassFish, and JavaDB are all working properly and we are ready to start developing our own Java EE applications.
.
[edit] Code Completion
The NetBeans code editor includes very good code completion. For example, if we wish to create a private variable, we don't need to type the whole "private" word, we can simply write the first three letters ("pri"), then hit Ctrl+Space, and NetBeans will complete the word private for us.
Code completion also works for variable types and method return values. For example, if we want to declare a variable of type java.util.List, we simply need to type the first few characters of the type, then hit Ctrl+Space. NetBeans will try to complete with types in any packages we have imported in our class. To make NetBeans attempt to complete with any type in the CLASSPATH, we need to hit Ctrl+Space again.
As we can see in the previous screenshot, NetBeans displays JavaDoc for the class we select from the code completion options. Another time saving feature is that the class we select from the options is automatically imported into our code.
Once we have the type of our variable, we can hit Ctrl+Space again, right after the variable, and NetBeans will suggest variable names.
When we want to initialize our variable to a new value, we can simply hit Ctrl+Space again and a list of valid types is shown as options for code completions.
In our example, our type (java.util.List) is an interface, therefore all classes implementing this interface are shown as possible candidates for code completion. Had our type been a class, both our class and all of its subclasses would have been shown as code completion candidates.
When we are ready to use our variable, we can simply type the first few characters of the variable name, then hit Ctrl+Space.
When we wish to invoke a method in our object, we simply type the dot at the end of the variable name, and all available methods are displayed as code completion options.
Notice how the JavaDoc for the selected method is automatically displayed.
Code completion also works for methods. We simply need to type the first few characters of our method name and NetBeans will automatically complete the method name, and it will also try to guess the values to pass as parameters.
[edit] Code Templates
Code templates are abbreviations for frequently used code snippets. To use a code template, we simply type it into the editor and hit the Tab key to expand the abbreviations into the full code snippet it represents.
For example, typing sout and pressing the Tab key will expand into System.out.println("");, with the caret placed between the two double quotes.
Some of the most useful code templates are listed in the table below, please note that code templates are case sensitive.
| Abbreviation | Example Expanded Text | Description |
|---|---|---|
Psf
| public static final
| Useful when declaring public static final variables. |
forc
| }
| Use a standard for loop to iterate through a collection. |
fore
| }
| Use the enhanced for loop to iterate through a collection. |
ifelse
| }
| Generate an if-else conditional. |
psvm
| }
| Generate a main method for our class. |
soutv
| +
| Generate a System.out.println() statement displaying the value of a variable.
|
trycatch
| }
| Generate a try/catch block. |
whileit
| }
| Generate a while loop to iterate through an Iterator. |
To see the complete list of code templates, click on Tools | Options. Click on the Editor icon, then on the Code Templates tab.
We can add our own templates by clicking on the New button. We will be prompted for the template's abbreviation. Once we enter it our new template will be added to the template list and will automatically be selected. We can then enter the expanded text for our template in the Expanded Text tab.
[edit] Additional References
For instructions on Troubleshooting Netbeans, click here
[edit] Source
The source of this content is Chapter 1: Installing Netbeans of Java EE 5 Development with NetBeans 6 by David Heffelfinger (Packt Publishing, 2009).
