Using Subversion, NetBeans IDE, and Sun Java System Web Server With Java ME

   
By Richard Marejka, January 2008  

A great deal of software is available to developers, even in what many would consider the small Java Platform, Mobile Edition (Java ME) space. With so much choice, it's difficult to determine which software products provide a real benefit. This technical article will highlight two products that improve the life of the Java ME developer by adding support for source-code management and application deployment.

The Problem

A source-code management (SCM) product manages multiple versions of project files, allowing you to save new versions, revert to older versions, and compare versions. This is valuable feature when your last change resulted in the introduction of a regression -- a technical term for "You just added a bug to the project." Most newer SCMs go well beyond the versioning of individual files present in the original SCM -- the source-code control system ( SCCS) developed at Bell Labs.

Every developer should use SCM, even for small projects. The small project inevitably turns into a larger project, even if the incremental growth is merely fixing bugs or adding features. The ability to track and manage software over time is a key factor to achieving success.

Application deployment can be problematic: getting the right files -- Java Descriptor (JAD) and Java Archive (JAR) -- to the right place, somewhere below the document root (docroot), on some web server. It's much easier to have an automated solution than to have to remember a manual procedure at the end of a development iteration.

This technical article uses the following components:

Subversion

Subversion, often called SVN, is a popular open-source SCM system that runs on a large number of platforms. For this article, the SVN server runs on a Sun Ultra 25 workstation, and the client software runs under Windows XP. The server installation used the packages available from Sunfreeware.com, a popular site for open-source packages that are available for a long list of Solaris OS releases.

To install, I simply downloaded pkgtrans and pkgadd. The only negative in the process was downloading and installing the 11 other packages that Subversion required on Solaris 10 OS.

I store all my SVN repositories in a single directory. This simplifies the SVN server runtime environment. It also facilitates backup of the various repositories.

The server is started with the system using the /etc/init.d mechanism. The SVN rc file /etc/init.d/svnserve contains the following:

#!/sbin/sh
#
# SVNSERVE - manage the SVN server.
#

case "$1" in
'start')
        if [ -x /usr/local/bin/svnserve ]; then
                /usr/local/bin/svnserve -d -r /export/home/shared/svn/
        fi
        ;;

'stop')
        if /usr/bin/pgrep svnserve >/dev/null 2>&1; then
                pkill svnserve
        fi
        ;;

'restart')
        /etc/init.d/svnserve stop
        /etc/init.d/svnserve start
        ;;

esac

exit 0
 

This is hard linked to /etc/rc2.d/S98svnserve. The result is that when the system starts, the SVN server starts.

Web Server

I use Sun Java System Web Server 7.0.

The installation is standard for Solaris OS: I set the target directory to /opt/webserver7 and selected the start server at boot time option. Just as I have all SVN repositories in a single directory, I keep a number of docroots in a single directory. The container directory is /export/home/shared/docroots. Again, this facilitates backup and provides the ability to easily switch docroots as requirements dictate. I set the docroot directory in this exercise to /export/home/shared/docroots/marejka.dyndns.org/.

Netbeans IDE supports Web-based Distributed Authoring and Versioning ( WebDAV) as one of its deployment protocols, and the web server supports WebDAV. So I used WebDAV as the MIDlet suite deployment protocol.

Once the server was up and running, I followed these configuration steps to enable the WebDAV deployment of MIDlets through Netbeans IDE:

  • Create a directory on the server (peg) under the docroot for the deployed JAD and JAR files.
  • Use keyfile authentication to create a user and password pair required for WebDAV access.
  • Enable WebDAV at the server level.
  • Create a WebDAV collection at the virtual-server level.
  • Add the MIME type for JAD files to the server.

The /jadpool Directory

We need some place under the web server's docroot from which to serve our JAD and JAR files. I chose the directory name of jadpool, a play on the phrase gene pool.

Creating the directory on the server is simply a matter of using this code as user root:

    cd /export/home/shared/docroots/marejka.dyndns.org
    mkdir jadpool
    chown webservd:webservd jadpool
 

The result is shown in Figure 1.

Figure 1: Webserver Root Document Directory Listing.
 

Authentication
I won't go into detail about authentication, which is a rather straightforward process. Within the browser-based Web Server Admin Console and under Configurations > peg, I selected the Access Control tab and peformed two tasks:

  • Created a type Key File authentication database named keyfile
  • Created a user -- for example, richard -- and gave the user a password

Note that I did not create any groups, and no Access Control Lists (ACLs) were created or modified.

WebDAV
To enable WebDAV on the server requires selecting a single checkbox. This checkbox was on the Configurations > peg page, tab General, secondary tab WebDAV. I selected it, as shown in Figure 2, and verified that the authentication database referenced the keyfile I had created.

Figure 2: Enabling WebDAV at the Server Configuration Level.
 

Next I needed to create a WebDAV collection at the virtual server level. Again using the Web Server Admin Console, I drilled down to the Configurations > peg > Virtual Servers > peg page and selected the WebDAV tab as shown in Figure 3.

Figure 3: Virtual Server -- WebDAV Collections.
 

Selecting New brought up a New WebDAV Collection pop-up window. I specified the URI as /jadpool and left the Source URI blank, then clicked Next. Figure 4 shows the initial WebDAV creation page.

Figure 4: WebDAV Collection Creation -- URI Information.
 

Clicking Next led to the Access Control page, as shown in Figure 5. Being security conscious, I restricted access by selecting the "Allow the following users in the authentication database" option and listed myself in the list of user IDs.

Figure 5: WebDAV Collection Create -- Access Control.
 

One more Next and I was on the Review page as shown in Figure 6. A quick review of the parameters and a daring click on Finish created the collection.

Figure 6: WebDAV Collection Create -- Review and Go.
 

I was able to confirm my /jadpool WebDAV collection properties when needed by using the collection property page. Starting on the same page as in Figure 3 and selecting an existing collection, I was presented with a properties page as shown in Figure 7.

Figure 7: WebDAV Collection Properties -- /jadpool.
 

MIME Types
Lastly, I added the MIME type for MIDlet suites to the web server. Setting the MIME type on the server means that a request for a JAD file will not only supply the correct file but will also correctly set the Content-Type header in the HTML response. The MIME type for JAD files is text/vnd.sun.j2me.app-descriptor. I added this in the MIME Types subtab under the General tab in the web server's server configuration, clicked New, then OK, and I was done.

Figure 8 shows the result on peg.

Figure 8: Web Server MIME Types.
 

At this point, the server side is installed, configured, and running. If the server is restarted, the web server and Subversion services will be restarted as well. Now let's turn to NetBeans IDE.

NetBeans IDE

Adding Subversion support to NetBeans IDE requires two very simple steps. First, add the Subversion module by using the Tools > Update mechanism. Find SVN in the list, add it to the updates list, click a few more times, and it's downloaded and installed.

You will also need to download a Subversion client for Windows. I downloaded prebuilt binaries from subversion.tigris.org and installed them. Finally, restart NetBeans IDE so that it finds the Subversion client software you just installed.

Once you have restarted, you'll notice that Subversion appears on the project right-click menu and in the NetBeans IDE menu bar, as shown in Figure 9.

Figure 9: The NetBeans Project Menu.
 

SVN Import
Before you attempt that first commit to a repository, you have to ensure that said repository exists. This requires some server-side operations: creating the directory and establishing at least one authenticated user.

Use the following as root:

peg# cd /export/home/shared/svn
peg# /usr/local/bin/svnadmin create bonjour
peg# vi bonjour/conf/passwd
 

The password file should end up looking something like this:

[users]
richard = password
 

where password is, of course, something that is not obvious. You may also want to reduce permissions on the passwd file to this:

-rw-r-----   1 root     root    27 Nov 30 16:29 passwd
 

This allows only user root or group root the ability to read the file.

Now you're ready for the initial check-in, which NetBeans IDE calls an import. To start the process, go to the menu bar and select Subversion > Import into Repository. NetBeans will then take you through three steps. First, you specify the repository and authenticated user, as shown in Figure 10.

Figure 10: SVN Import - identify repository.
 

Second, NetBeans asks for the repository folder location, as shown in Figure 11.

Figure 11: SVN Import -- Specify Folder Name.
 

Finally, NetBeans shows you the list of files it will import, as shown in Figure 12.

Figure 12: SVN Import -- File Import List.
 

A few Nexts and a Finish and your source is safely saved into the Subversion repository.

SVN Check-Out

Once checked in, the project can be checked out by any Subversion client. Under the NetBeans IDE menu, select SVN > Checkout, and the Checkout window will appear. Enter the Repository URL. In this case, we use the internal URL svn://peg/bonjour and supply the user-password pair, as shown in Figure 13.

Figure 13: SVN Checkout -- Specify Repository.
 

Next, select which folders to check out, as showin in Figure 14. The Browse option is great for visually examining the repository to select content. Once you have selected the checkout content, click Finish.

Figure 14: SVN Checkout -- Identify Folders.
 

NetBeans IDE will detect that you were checking out a project and give you the option to open the project. Select Open Project, as shown in Figure 15.

Figure 15: SVN Checkout -- Open Project Option.
 

Once the project is open, select Clean and Build Main Project to make certain that you have all the pieces in working order.

You can now make whatever modifications you have planned to the source. Add features, fix bugs, or tune algorithms in your own project space. You can use the emulator to test your changes before deployment using the Run > Run Main Project menu item.

Deployment
Eventually, you will want to test your MIDlet in the real world. There is nothing more real than over-the-air (OTA) installation to a device. However, creating a MIDlet suite that can be installed and having it deployed to a web server can be a challenge.

This is where that sometimes difficult process becomes easy. Deployment of a MIDlet suite requires putting a JAD and JAR file under the docroot of some web server. The JAD file describes the MIDlet suite that is contained in the JAR file by using MIDlet attributes.

The article Retrieving MIDlet Attributes provides greater detail on JAD file syntax and contents. Eight attributes are required in the JAD file to define a MIDlet suite that can be successfully installed on a device. The JAR file contains the MIDlet suite and all its required resources. NetBeans IDE's automated deployment feature will not only install the files on the web server, it will automatically generate a correct JAD file. Note that any user-added content under the Application Descriptor category will also be added to the generated JAD file.

The first time you go through the automated deployment process, you have to supply all the form data in the Deploying category of the project properties. Select the WebDAV deployment method, and supply the server name or IP address with port number, the target directory, and the WebDAV user-password pair. On the web server, all JAD and JAR files are kept in one directory: /jadpool. Again, keeping like things in one place makes both deployment and backup easier to manage. Note that I used the Override JAR URL in JAD option, as shown in Figure 16, because the server name (peg) for deployment is local to my network, whereas the published URL uses the Internet-visible server name of marejka.dyndns.org.

Figure 16: NeBeans Project Deployment Properties.
 

Once you have populated all the Deploy category data, right click on the project and select Deploy to push the JAD and JAR files to the server. If you have correctly configured the server, the deployment process completes in less than one second.

Download

The final test is installing the application to your device OTA from your web server. This process will vary for each device, but the steps are essentially the same:

  • Start the browser on your device.
  • Enter the URL of the deployed JAD file, for example, http://marejka.dyndns.org/jadpool/bonjour.jad.
  • Accept the download.
  • Launch and test the application on your device.

If you are interested in more extensive on-device and on-network testing, Mobile Complete is one company that sells just such a service. Pick a carrier, a location, and a device, and you can test your application live in the field with this service. Mobile Complete has been at the JavaOne conference in the past and is sometimes at Sun Tech Days events.

Conclusion

I was somewhat skeptical when I started investigating the tie-in between Subversion, NetBeans IDE, and WebDAV. Product add-ons sometimes do not work well together, fail to meet user expectations, or are awkward or difficult to use. In this case, everything worked as expected. The NetBeans Subversion module and the Mobility Pack combined with Sun Java System Web Server save time and simplify two important development tasks. Now that I have the Subversion server and Sun Java System Web Server installed on my Ultra 25 workstation, I will continue to use them on subsequent projects.

Rate and Review
Tell us what you think of the content of this page.
Excellent   Good   Fair   Poor  
Comments:
Your email address (no reply is possible without an address):
Sun Privacy Policy

Note: We are not able to respond to all submitted comments.