This tutorial demonstrates how to use remote development of C/C++ projects. Have you ever wanted to
develop a SolarisTM or Linux application from your laptop running Windows 7 or Mac OS X?
To test your application on different operating systems without even leaving the
IDE? Or just to compile your large applications on a fast multicore
server rather than on your regular workstation. The answer to all
these needs is the remote development functionality in NetBeans IDE 6.9.
Please take a look at this tutorial to find out how to use this
feature.
Remote Development Concepts
Remote development works this way:
Run the NetBeans IDE on your client system and you can create projects,
edit files, and use code assistance features the same way as you do for
local projects. But when you build, run, or debug your project, the process runs on the
remote server with output and input transferred to the client system. So,
ideally, you shouldn't see any difference in workflow between doing
local and remote development once you've set up the remote development host.
The elements that must be in place to enable the use of a remote host for running
your tools are:
The local client system and remote system must have access to the project files, either
through shared resources, or through use of Secure Shell protocol (SSH).
The client must be able to connect to the remote system through a secure shell (ssh) even
if the project files are on shared folders.
The remote system must have access to a supported tool collection.
The remote system must have the supporting system libraries that your project needs
to enable code assistance.
Each of these requirements are explained below.
Sharing sources
Both your client system and your remote server have to know about your source
files. The source files can reside on a shared network path, or can be copied securely
by the IDE from the local system to the remote system. In the section
Setting Up the System you can find more details about ways to set
up shared folders for different systems.
Connectivity
All data transfer between client and server except shared network path is done
through the Secure Shell (SSH) protocol. SSH is a common protocol for secure
communications between two networked devices.
Your server has to have the SSH server installed, and SSH connection
between the client system and the server should be allowed.
Tool Collections
The IDE must be able to find a supported tool collection: GNU Compiler Collection
or Sun Studio or Oracle Solaris Studio. The tools executables should be on the path of the user
account used to connect to the remote host, so the IDE can easily locate the tools. This is
especially true if the tools are installed in a non-default location.
Code Assistance
For correct support of editor features like code completion and
semantic highlighting, the Classes window, and others, your project has to be
used in the correct environment, which means system includes, macro
definitions, platform, etc. All of this information is gathered from the
remote server and stored locally on your client system, so that when you
edit locally the code assistance will work even when the project is set up to
use a remote development host.
Setting Up the System
Your remote server must allow communication through the SSH protocol from the client
where you are running the IDE. If you want to use file sharing instead of allowing
the IDE to copy files to the remote server, the file sharing must be set up in
the network for both systems.
SSH protocol
The SSH server is usually included in Linux and Solaris
operating systems, and is run by default in most cases. If not, you
can find information about installing and managing SSH at http://en.wikipedia.org/wiki/Secure_Shell
The IDE provides its own ssh client, so you do not need to install
the ssh client on your local machine.
An SSH connection must be allowed between your client and server
systems, which usually means port 22 must be open on the server. You
may need root access or the help of your system administrator if port 22
is disabled.
SSH must be enabled between the systems even if you are not using
the Smart Secure Copy option to transfer the projects files to the
remote server.
Sharing sources
If you do not already have file sharing set up between your Windows system and a Unix remote
host for other uses, it is much simpler to use Smart Secure Copy option instead of file sharing.
For Windows to UNIX® configuration there are two major ways of sharing sources:
Samba server on UNIX system
Windows Services for UNIX (SFU) package installed on Windows system
Organizing sources using Samba
A Samba server allows a Windows user to map shared NFS folders as
Windows network drives. The Samba package is included in most distributions of Linux and
Solaris operating systems. If it's not included in your distribution,
you can download it from www.samba.org
If you have root access on your server, you can set up Samba yourself
following the simple instructions at the following links. Otherwise you have to contact your
system administrator.
After starting Samba you can map your UNIX server's folders the same way as Windows
folders.
Windows Services For UNIX (SFU)
Another option is Windows Services For UNIX, a set of utilities provided by Microsoft to
access NFS filesystems from Windows.
You can download them from Microsoft Download Center and
read documentation at Windows Services for Unix page.
The SFU package is not available for Windows Vista or Windows 7 users. Windows Vista and Windows 7 Enterprise and Ultimate Editions include the Services for Unix components,
renamed to the Subsystem for UNIX-based applications (SUA), and Client for NFS v3.
For more information, see
http://en.wikipedia.org/wiki/Microsoft_Windows_Services_for_UNIX
Mac OS X configuration
Mac OS X includes support for connecting to Samba servers. Mac OS X can also mount NFS shares from a server.
You can use Finder > Go > Connect to Server and enter a server address.
To connect to SMB/CIFS (Windows) servers and shared folders, enter the server address in
one of these forms:
You are not prompted for your username and password, but authorization
is checked against your Mac UID. The UID is a unique integer assigned to your
username in Unix-like operating systems such as Mac OS X, Solaris, and Linux.
To use NFS, the Mac UID must be the same as the UID of your account on
the server.
UNIX-UNIX configuration
For file sharing between Solaris or Linux systems you don't need any
special setup. You just need to share a folder from one of the systems
or you can use your home directory if it is mounted on a network file server
and accessible from both systems.
Path Mapping
When using the shared sources model, you may need to map the location of the sources on the local
host, to the path used on the remote host to get to the sources.
For example, consider this configuration:
Solaris server solserver with shared folder /export/pub
Workstation running Windows XP with installed SFU and path
\\solserver\export\pub is mounted as drive P:
Project source files located on solserver in the folder
/export/pub/myproject
In this case from the server point of view your source files are located in
the /export/pub/myproject. But from the client point of view the location
of the source files is P:\myproject.
Hence you need to let the IDE know that these paths are mapped:
/export/pub -> P:\
If you set up shared resource for source files before configuring
the remote host in NetBeans IDE, the IDE will automatically find out the required path
mappings for you in most cases.
Setting Up the IDE
In the following example, the client host is
a workstation running Windows Vista. The remote host named b20 is a
server running the Solaris operating system.
Open the Services window by choosing Window > Services.
Right-click the C/C++ Development Hosts node and select Add New Host.
In the New Remote Development host dialog box, the IDE discovers your
local network's hosts. The host names are added to a table in the dialog box,
and marked Available if they are running the SSH server.
Double-click the name of the server you want, or type the server name directly
in the Hostname field. Click Next.
On the Setup Host screen, type the username that you use to log in to the remote host, and select
an authentication method. For this tutorial, select Password and click Next.
If you want to use ssh keys, you must set them up outside the IDE first. Then you can
specify the location to the ssh keys in the IDE, and the IDE can use the keys to make the ssh connection
to the remote development host.
After a connection is made to the server, enter your password in the Authentication dialog box.
Optionally, click Remember Password to have the IDE encrypt and store the password on your local disk so you
do not have to enter it each time the IDE connects to the remote host.
The IDE configures the remote host and looks for tool collections on the remote host.
When the host is successfully configured, a summary page shows information about the
remote host: the platform, hostname, user name to log in, and the tool collections that were found.
At the bottom of the summary page, two more options are displayed.
If more than one tool collection was found, you can select one of the collections
to be the Default Tool Collection.
For the Synchronization option:
Select Smart Secure Copy if your client system and the remote
development host do not have shared access to the project files. When you select Smart Secure
Copy, the project files will be copied to your home directory on the server using the scp or sftp command.
Select File System Sharing (no synchronization) if the client and server have access to the same
folder.
Click Finish to complete the wizard.
In the Services window, the new remote host is shown under the C/C++ Development Hosts node. Expand
the node for the new host and you should have one or more tool collections in the Tool
Collections list.
If no tool collections are listed:
On the remote host, add the tool collection's bin directory to your user path on the host.
If no tool collections are available on the remote host, you must install the GNU compiler collection
or the Sun Studio or Oracle Solaris Studio software on the remote host.
When the path to the tool executables is on your remote host user path, you can try
to set up the tool collection on the local system again. Right-click the host in the Services
window and select Restore Default Tool Collections to have the IDE try to find
tool collections on the remote host again.
Alternatively, right-click the host in the Services window and select Add Tool Collection to specify
or browse to the path to a tool collection on the remote host.
When you have a tool collection listed, you are done with
creating your new remote development host. Let's see how can you use it for
development.
Building a Local Project on a Remote Host
Let's create a new sample project by choosing File > New Project.
Expand Samples > C/C++ and select the Welcome sample project and click Next.
In this example, we are not using shared folders, so we can keep the suggested location
for the project in the NetBeansProjects folder in the Windows user directory, which is not shared.
If you want to use shared source files, make sure that as a Project Location you are choosing a path
that is shared with the remote server.
Select the new remote host for the Development Host. The Tool Collection list is updated
to show the available tools on the remote host.
Click Finish to create the project. Notice that when you place the mouse over the name
of the project in the Projects window, a tooltip shows the project location and the remote host that
it is configured to build on.
Now click Build on the toolbar or right-click the project node and choose
Build, and the sample project will be built remotely on the selected development host.
In the following screenshot you can see in the tooltip that your source file is
located on the local machine and code assistance support is working when
you press Ctrl-Space with the cursor on the argc symbol.
In the Output window you can see the name of the host where the
application was built and that remote compilers and make utility were used for building.
The project files are in the user's .netbeans/remote/system-platform directory on the remote host.
There is almost no difference in workflow once you set up a remote
host. You can use all editor features, build, run, test, and debug as you are
used to doing locally.
Starting a Terminal Session on the Remote Host
You can start a secure shell terminal session from within the IDE to connect to the remote
system or the local system. This feature is especially convenient on Windows platforms,
which do not support SSH natively.
In the IDE, select Window > Output > Terminal to open the Terminal tab, which you
can use to start a terminal session on the local or remote host.
Click the Create Remote Terminal button to open the SSH Connection dialog box.
Enter the username and hostname and click OK.
The IDE starts a ssh session to the specified host and the Terminal tab shows your login
prompt on the remote host.
Go to your $HOME/.netbeans/remote directory to see your project files, which by
default are stored in subdirectories that indicate the local system name and platform
where the project was created.
You can use the IDE internal terminal to do anything you might usually do in a ssh
session to a remote host.
Remote Development Tips
You can switch the development host for a project by right-clicking the project node
and selecting Set Remote Development Host.
You can change the properties of a remote development host after initial setup, by right-clicking
the host in the Services window and selecting Properties.
If you are using a remote host to build and run an application with a graphical UI, you can select
Enable X11 Forwarding in the hosts properties to that the UI can be seen on your local system while it runs on the
remote host.
You can access the remote host and tools information from the IDE's Tools menu as well as the
Services window. Select Tools > Options > C/C++ > Build Tools and click the Edit
button next to the Development Host list.
When using file sharing for project files, you can map the local and remote paths to the shared folder through
the Path Mapping feature. You can set the mapping by selecting Tools > Options > C/C++ > Build Tools
> Edit. Then select the remote host and click the Path Mapping button.
If building your project remotely compiles libraries or generates other files in addition to the main build product,
the IDE prompts you to download the files to the local system. You can select which changed files
to download.
More Information about C/C++/Fortran Support
Please visit the C/C++ Learning Trail for more information
about using the C/C++/Fortran features of the IDE.