当前页面: 开发资料首页 → Netbeans 专题 → Building and Running Java PathFinder with NetBeans
摘要: This document illustrates how easy it is to get a NetBeans development environment up and running for the Java PathFinder SourceForge.net project. As you will read in this document, using NetBeans as the development tool for building and running Java PathFinder is very simple.
The instructions in this document are presented from a Windows user's perspective. Solaris and Linux users should substitute path names, installation program names, etc. for their platforms where applicable.
Note: The installation instructions assume that you download all of the components into C:\tmp.
Note: The installation instructions below assume you download the Windows version of the JDK.
Note: Unless you are planning to do J2EE development, you can download the NetBeans 4.1 RC installer, (netbeans-4_1-rc1-windows.exe) version.
This is a single file, jpf-lib.zip, that contains .jar files needed by Java PathFinder.
After downloading all of the components, install them by following the instructions below.
Go to the C:\tmp directory where you downloaded the JDK and double click the jdk-1_5_0_02-windows-i586-install.exe file to initiate the installation of the JDK. Follow the instructions given by the JDK installer to install the JDK.
Go to the C:\tmp directory where you downloaded NetBeans and double click the netbeans-4_1-rc1-windows.exe file to initiate the installation of NetBeans. Follow the instructions given by the NetBeans installer to install NetBeans.
Now that you have the necessary environment to build Java PathFinder, you are ready to launch NetBeans, get the Java PathFinder source code, build Java PathFinder from source and run Java PathFinder all from within NetBeans.
To launch NetBeans, double click the NetBeans 4.1 icon on your desktop. Or, if you are on Solaris or Linux, launch NetBeans by typing netbeans in a terminal window.
The next step is to configure the NetBeans IDE to retrieve the Java PathFinder source code from the sourceforge.net CVS repository.
In the NetBeans IDE, from the main menu select Versioning > CVS > Check Out as shown in Figure 1 below.
After you have selected the Versioning > CVS > Check Out menu item, the you will see the "Enabling Advanced CVS Command Options" dialog as shown in Figure 2.
If you do not want to see this dialog in the future, go ahead and mark the checkbox next to the label "Do Not Show This Dialog Box Again" as shown in Figure 2 above and press the "Check Out" button.
Next you will see the "CVS Checkout" dialog. There are several values you will need to enter on this screen. Each of the values below should be entered in this screen.
Working Directory: <source path where to place Java PathFinder source files>
Remember this directory path, you will need to know it again later
CVS Server Type: pserver CVS Server Name: cvs.sourceforge.net Port: 2401 User Name: anonymous Repository Path: /cvsroot/javapathfinder
Select "Use Built-in CVS Client"
Password: <leave this blank>
Leave the Modules and Revision fields blank
Module(s): <leave this blank> Revision or Tag: <leave this blank>
Your CVS Checkout form should look very similar to the one shown in Figure 3 below.
You need to login if you see the message "You are not logged in." below the Password field and Login button. If you see this message, Press the Login button now. The label will change to "You are logged in" as shown in Figure 3 above.
The CVS Checkout form from my development environment is shown in Figure 4 below.
Once you have the CVS Checkout form completed and it says you are logged in, press the "Ok" button.
After you have pressed the "Ok" button, the CVS Checkout form will go away and you will notice the output window, the bottom portion of the NetBeans IDE, will display the VCS Output from running your CVS checkout. The output in this VCS Output window should look very similar to that shown in Figure 5 below.
When the CVS checkout is completed, the status message at the bottom of the VCS Output window will say it has finished the Check Out.
Now that a folder for the Java PathFinder source is on your system, you will next unzip the jpf-lib.zip file.
When you specified a working directory for the CVS Checkout, NetBeans created a javapathfinder folder in that working directory. That javapathfinder folder contains a lib folder. The lib folder is where PathFinder's build.xml expects to find these three .jar files: bcel.jar, fast-MD5.jar, and xercesImpl.jar. Unzip the contents of jpf-lib.zip to your javapathfinder folder.
Now that you have the Java PathFinder source files locally on your system, you will next create a NetBeans project to build and run Java PathFinder.
Select File > New Project from the main menu as shown in Figure 6 below.
After selecting the File > New Project menu item, a New Project wizard will be displayed as shown in Figure 7.
In the New Project wizard, select the General project category and Java Project with Existing Ant Script project type as shown above in Figure 7. Then, press the Next button. This will bring up the second screen of the New Project wizard. On this form you specify the location of the project files, the Ant build script, supply a project name and a project folder.
For the Location field, browse to the directory you specified as the working directory earlier when you told NetBeans to download the source files for Java PathFinder and select the "javapathfinder" directory as the location of the Java PathFinder source file location. The NetBeans IDE will automatically find the Ant build script and specify a project name and project folder. You can accept the defaults NetBeans has chosen for the project name and project folder or change them if you wish.
An example screen shot of the values used in my development environment along with the default values NetBeans automatically filled in for the project name & project folder is shown in Figure 8 below.
After selecting the project name and location, press the Next button. This will take you to the Build and Run Actions form of the New Project wizard. You will notice that NetBeans will automatically map Ant build targets to NetBeans actions. An example of the mapping NetBeans has automatically chosen are shown in Figure 9 below.
Press the Next button to accept the default mappings. (Note: You can change any of the default mappings by simply selecting one of the dropdown boxes and selecting a different Ant build target.)
After pressing the Next button, the Source Package Folders form of the New Project wizard is displayed. On this form you specify the source directories for your project. To add the source package folder click on the Add Folder button in the Source Package Folder section of this form. Traverse to the directory you specified earlier as the Working Directory in the CVS form and open the javapathfinder directory. Then, select and open the src folder. Then, add the test package folder by pressing the Add Folder button in the Test Package Folders section of the wizard. Traverse to the directory you specified earlier as the Working Directory in the CVS form and open the javapathfinder directory. Then, select and open the test folder.
The last thing to set on this form is the Source Level. Set the source level to JDK 1.4 by selecting the Source Level dropdown box and choosing JDK 1.4.
Your Source Package Folders wizard should look like the one shown in Figure 10 below.
Press the next button to go to the Java Sources Classpath form. On this form you tell NetBeans where to find the three additional components (BCEL, Xerces and MD5) to be used by the editor for tasks such as syntax checking, code completion and import statements. The .jar files for these three components are located in the javapathfinder/lib folder.
Add each of the three components on this form. An example screen for after adding these three components for my development environment is shown in Figure 11 below.
After adding the three components, press the Finish button.
You will now notice in the NetBeans project window a new project is shown. Your NetBeans project window should look like to the one shown in Figure 12.
You now have successfully created and configured a Java PathFinder project in NetBeans. You are now ready to build and run Java PathFinder in NetBeans.
In the NetBeans project window, right click on the newly created Java PathFinder project. You can choose to build the project which will compile the Java PathFinder project or you can choose to run the project which will both build the project and run the Java PathFinder test suite.
When you right click on the Java PathFinder project in the project's window, you can see options such as those shown in Figure 13 below.
Select, "Run Project", as shown in Figure 13 to run the project. This will initiate a build of the Java PathFinder project if it has not already been built and run a suite of tests after it is built. You will notice in the bottom of the NetBeans IDE, the output window will show the results of building and running the Java PathFinder project. An example of the NetBeans output window from building and running the Java PathFinder project is shown in below.
That's all there is to having an environment where you can build and run the Java PathFinder in NetBeans. Simple isn't it?