NetbeansedAzureus
How to Work with Azureus in the NetBeans IDE </div>
By: Daria Titova
November 2007
In this tutorial, you will convert Azureus to a NetBeans project and learn how to build, run, debug, and profile Azureus in the NetBeans IDE. </span>
Contents |
Introduction
Azureus implements the BitTorrent protocol using Java language and comes bundled with many invaluable features for both beginners and advanced users: multiple torrent downloads, upload and download speed limiting, both globally and per torrent, advanced seeding rules, adjustable disk cache, only uses one port for all the torrents, can use a proxy, for both tracker and peer communications, fast resume and others. Azureus also has many useful plugins.
This tutorial shows you how to use the NetBeans IDE for Azureus development.
The NetBeans Integrated Development Environment (IDE) is a free, open-source Integrated Development Environment for software developers. The NetBeans IDE provides developers with all the tools they need to create professional cross-platform desktop, enterprise, web, and mobile applications.
In this tutorial, you learn how to convert the Azureus project into a NetBeans project to develop, debug, and profile the Azureus within the NetBeans IDE.
In the Exercises section, you will use the preconfigured Azureus NetBeans project and perform run, debug, and profile actions. In the Appendix section, you can find detailed steps for creating a Azureus NetBeans project from scratch.
For more information on how to work with the NetBeans IDE, see the Support and Docs page.
Software needed
Before you begin, you need to install the following software on your computer: NetBeans IDE 6.0.
Use NetBeans IDE 6.0 available from NetBeans IDE 6.0 Download.
Notations used in this Documentation
- <NETBEANS_HOME> - the NetBeans IDE installation directory
- <USER_HOME> - the user's home directory. Example: "C:\Documents and Settings\user_home" for Windows OS.
- <azureus_root> - the directory with Azureus sources
Exercises
Converting Azureus to a Netbeans Project
To download the Azureus sources:
1. Download the Azureus source code from CVS repository to the <azureus_root> directory. CVSROOT=:pserver:anonymous@azureus.cvs.sourceforge.net:/cvsroot/azureus (the password is empty). You need to download the azureus2 directory.
To create the Azureus NetBeans Project:
1. Download the attached nbproject_NetbeansedAzureus.zip file, and extract it into the <azureus_root> directory. Now you see <nbproject> directory and build-nb.xml file under the <azureus_root> directory.
For more details on how the Azureus NetBeans project has been created see Appendix.
2. In the IDE, choose Open Project from the main menu and open the Azureus project from your <azureus_root> directory.
Now you see the Azureus free-form project in the Projects window.
Note: The project will be marked with a red exclamation mark. This means there are some classes and/or jars which NetBeans does not know the path to. If you want to eliminate red exclamation marks, specify the path to classes in the NetBeans IDE. This tutorial does not cover the details of eliminating exclamation marks because they do not break project building, running, and debugging.
Note: To view project's packages as tree right-click Projects Window and choose View Java Packages as > tree from the pop-up menu.
Running the Azureus Project
To run the Azureus project files, do the following:
1. In the Projects window, right-click the Azureus project node and choose Run from the pop-up menu.
The IDE will compile the Azureus source and run Azureus.
Debugging Azureus
1. Open the Main.java class from the com.aelitis.azureus.ui package and set a breakpoint at line 41.
2. Right-click the Azureus project node and choose Debug from the pop-up menu.
The IDE opens the Debugger windows and runs Azureus in the debugger until the breakpoint is reached. You can perform Step Into, Step Over, and other debugging activities.
To finish debugging, close the running Azureus application or press the Finish button in the toolbar:
For detailed tips on how the Debug action has been made for Azureus see the Appendix section.
Profiling Azureus using the Netbeans Profiler
1. In the Projects window, right-click the Azureus project node and choose Profile from the pop-up menu. If the Azureus project is set as main, you can press the Profile Main Project in the toolbar
.
2. In the Profile Azureus window, accept the default "CPU > Analyze Performance" option and click Run.
3. In the Select Task for Profiling window, select the profile task from the checkbox, and click OK.
The Profiler tab opens in the Netbeans IDE and the Profiler collects information about running Azureus.
Appendix
This section describes how to create a NetBeans Project for Azureus from the scratch.
After downloading the Azureus source into <azureus_root> (see the Converting Azureus into a Netbeans Project section for details), do the following:
Creating the Azureus NetBeans project
1. Create build-nb.xml file under the <azureus_root> directory, containing the following:
<?xml version="1.0" encoding="UTF-8"?> <project name="Azureus" basedir="."> <import file="./build.xml"/> </project>
This step is required because we do not want to change the original Azureus structure, and we do not want to change Azureus's build.xml file.
For adding extra Ant targets for the Azureus NetBeans project (which are not in the Azureus's build.xml, like run, debug, etc.). So we created a new file, build-nb.xml, under the <azureus_root> directory and will define the extra Ant tasks in this file. For details, see the Adding extra actions for the Azureus NetBeans project section.
2. From the main menu, choose File > New Project.
The New Project wizard opens.
3. In the Categories list, select "Java", in the Projects list, select "Java Project with existing ANT Script," and click Next.
4. At the Name and Location page, specify the following values in the fields listed below:
- Location - <azureus_root>
- Build Script - <azureus_root>/build-nb.xml
In this case, the Azureus project files are located at C:\work\azureus2.
Click Next.
5. At the Build and Run Actions page, specify the following Ant targets in the fields listed below:
- Build Project - compile
- Clean Project - clean
- Generate Javadoc - empty
- Run Project - empty
- Test Project - empty
Click Next.
6. At the Source Package Folders page of the wizard, specify <azureus_root>as the source package folders.
7. Click the Includes/Exludes button and specify the following values in the fields listed below:
- Includes: com/**/*.java, org/**/*.java
Click Next.
8. At the Java Sources Classpath page, add the following items to the Java Sources Classpath list for packages:
- commons-cli.jar under the <azureus_root>/build/libs
- log4j.jar under the <azureus_root>/build/libs
- swt-win32.jar (or swt-xosx.jar) under <azureus_root>/build/libs
Click Finish.
The Projects window contains the project node for the Azureus project you have just created.
9. Specify the Output project property.
For the debugging action of the Azureus project we need to specify the Output project property. The debug action we will add in the next section.
In the Projects window, right-click the Azureus project node and select Properties.
In the Project Properties window, select Output in the Categories list and add the following directories to the output list for packages:
- the <azureus_root> directory. In this case it is the C:/work/azureus2 directory.
Click OK.
Adding extra actions for the Azureus NetBeans project
Standard NetBeans project actions are build, clean, generate javadoc, run, and test. You set some of these actions while creating the Azureus NetBeans project in step 5 (see Creating the Azureus NetBeans project). Here you will learn how to add run, debug, and profile actions to the Azureus NetBeans project.
1. Open the build-nb.xml file in the Editor window of the NetBeans IDE.
Adding the Run action to the Azureus project
To add the Run action to the Azureus project, you need to modify the build-nb.xml file and add Run action to the project's contextual menu.
1. Add the run Ant task to the build-nb.xml:
...
<path id="cp">
<pathelement path="./"/>
<pathelement path="./build/libs/swt-win32.jar"/>
<pathelement path="./build/libs/log4j.jar"/>
<pathelement path="./build/libs/commons-cli.jar"/>
</path>
<target name="run" depends="compile">
<java classname="com.aelitis.azureus.ui.Main" fork="true">
<classpath refid="cp"/>
</java>
</target>
...
This run task runs the Azureus application. A dependency is added here because you must compile code before running it. We also define classpath cp, which would be used in debug and profile tasks. The next section shows how to implicitly use this run task in the debug and profile tasks. To find out which class is the main class, review the Azureus code.
2. In the Projects window, right-click the Azureus project node and choose Properties.
In the Project Properties window, select Build and Run in the Categories list and set the Run Project combobox value to run.
You can view build-nb.xml in the attached nbproject_NetbeansedAzureus.zip file.
Adding the Debug action to the Azureus project
To add the Debug action to the Azureus project, you need to modify the build-nb.xml file and add Debug action to the project's contextual menu.
1. Add the debug Ant task to the build-nb.xml:
...
<target name="debug" depends="compile">
<nbjpdastart addressproperty="jpda.address" name="Azureus" transport="dt_socket">
<classpath refid="cp"/>
</nbjpdastart>
<java fork="true" classname="com.aelitis.azureus.ui.Main" classpathref="cp">
<jvmarg value="-Xdebug"/>
<jvmarg value="-Xrunjdwp:transport=dt_socket,address=${jpda.address}"/>
</java>
</target>
...
To define the debug task for this project, you need to specify the NetBeans specific task for debugging (<nbjpdastart>) and then run this task (which was done in the previous section) with the mandatory arguments for JVM that were specified in part of build-nb.xml pasted above.
For more information on how to add a debug project action, see Advanced Free-Form Project Configuration tutorial.
2. In the Projects window, right-click the Azureus project node and choose Properties.
In the Project Properties window, select Build and Run in the Categories list.
Click Add button to add custom contextual menu item, and set the following values in the fields listed below:
- Label - Debug
- Ant Target - debug
You can find build-nb.xml in the attached nbproject_NetbeansedAzureus.zip file.
Adding the Profile action to the Azureus project
To add the Profile action to the Azureus project, do the following:
1. Add the profile Ant task to the build-nb.xml:
...
<target name="profile" depends="compile">
<nbprofiledirect>
<classpath refid="cp"/>
</nbprofiledirect>
<java fork="true" classname="com.aelitis.azureus.ui.Main" classpathref="cp">
<classpath refid="cp"/>
<jvmarg value="${profiler.info.jvmargs.agent}"/>
</java>
</target>
...
To define the profile task for this project, specify a NetBeans-specific task for profiling (<nbprofiledirect>) and then run this task (which was done in the previous section) with the mandatory argument for JVM that were specified in part of build-nb.xml pasted above.
For more information on how to add the profile action, see tutorial.
We do not need to add Profiler contextual menu item because NetBeans Projects already has it.
Explore build-nb.xml in the attached nbproject_NetbeansedAzureus.zip file.
Summary
In this tutorial, you learned how to start Azureus development in the NetBeans IDE. You have completed the following exercises:
- Convert Azureus into Netbeans Project.
- Build Azureus in NetBeans IDE.
- Run Azureus in NetBeans IDE.
- Debug Azureus in NetBeans IDE.
- Profile Azureus in NetBeans IDE.
See Also
- How to Work with JRuby in the NetBeans IDE
- How to Work with Tomcat in the NetBeans IDE
- How to Work with JEdit in the NetBeans IDE
- How to Work with JUnit in the NetBeans IDE
- How to Work with Ant in the NetBeans IDE
- How to Work with Derby in the NetBeans IDE
- How to Work with SQuirreL in the NetBeans IDE
References:
- NetBeans IDE 6.0 Preview Documentation: http://www.netbeans.org/kb/60/index.html
- Got issues: http://www.netbeans.org/issues/enter_bug.cgi
- FAQ List: http://wiki.netbeans.org/wiki/view/NetBeansUserFAQ
Attachments


















