Wizard API updated!
Tim Boudreau has released a new version of the Swing Wizard library (version 0.997) that fixes the WizardException bug reported in JavaWorld's recent Open Source Java Project profile. The article's examples have been reworked to test out the new, improved WizardException. Thanks, Tim, for this helpful fix!
Open Source Java Projects: The Wizard API

Newsletter sign-up

Sign up for our technology specific newsletters.

Enterprise Java
View all newsletters

Email Address:

Master of disguises: Making JavaBeans look like ActiveX controls

Learn how to make your JavaBeans available to Windows programmers using tools from Sun and Microsoft

Life's tough when you're trying to develop reusable software components. Often, the development tools your customers use dictate which development tools and architecture you choose. As a component developer, you may be attracted to the simple, object-oriented architecture of JavaBeans. However, there are a lot of Visual Basic (Visual C++, Delphi, etc.) developers who want ActiveX controls, not JavaBeans. Are you ready to forfeit these potential customers? Wouldn't it be great if you could write your components in Java and make them available to ActiveX control users? Well, you can. And in many cases, you won't even have to modify your existing Java code!

The right tool for the job: Choosing between the Sun and Microsoft tools

Currently, both Sun and Microsoft have bridging tools that are freely available for download: the Packager application from Sun and javareg from Microsoft (see Resources). Which one you choose will depend a lot on your personal tastes. Each has its strong and weak points. In general, users of your bridged JavaBeans won't see much difference between the two solutions. Both solutions utilize a Java virtual machine (VM) that is loaded as a dynamically linked library (DLL) into the client application or development tool. It's important to note that both solutions load only one instance of the VM per client. This allows an application to "connect" multiple ActiveX controls to each other, and know that that their underlying JavaBean instances are running in a shared VM.

Unfortunately, neither of the toolsets earns points for its robustness. Both do a rather poor job of helping you diagnose problems with your controls. However, I did find Sun's BeanBox testing tool helpful in validating JavaBeans prior to running either bridging tool. In addition, both tools suffer from a lack of good documentation (as if anything ever comes with good documentation, right?) Fortunately, Sun provides reasonably responsive e-mail support for its JavaBeans Bridge. While Microsoft's free support is limited, the Java-COM list server is a good place to look for answers specific to tools. (See Resources for information on how to access these support services.)

Sun's JavaBeans Bridge for ActiveX 1.0

The first tool we'll examine is the Packager application, which comes as part of Sun's JavaBeans Bridge for ActiveX. Packager allows you to:

  • Generate Windows-friendly event interfaces
  • Generate standard, easy-to-use registry files
  • Require separate jar files for ActiveX users


We'll examine each of these aspects in the following discussion.

Packager is a Java application that has both graphical and command-line interfaces. To use it, you place your JavaBean(s) in a jar file along with any supporting code or resources. Note that your beans must belong to a package other than the default package, otherwise the Packager will crash, leaving you with nothing but a cryptic error message about string parsing.

Packager's GUI guides you through the process of bridging your JavaBeans. You first select the jar file and JavaBean you wish to bridge, as well as the name for the ActiveX control and destination directory for the generated files. One nice feature is Packager's ability to "uncrack" Java events so they're delivered as their component parts -- much like events from "native" ActiveX controls -- rather than single event objects. The example below shows a typical Java event class:

1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |  Next >
Resources
  • Download examples for this article http://www.javaworld.com/jw-09-1998/bridge/jw-09-bridge-examples.zip
  • Download the Packager, included with Sun's JavaBeans Bridge for ActiveX http://java.sun.com/beans/software/bridge/
  • Download javareg, included with Microsoft's SDK for Java 3.0 http://www.microsoft.com/java/sdk/default.htm
  • Join the Java-COM mailing list for help with Microsoft's Java tools http://discuss.microsoft.com/archives/java-com.html
  • E-mail Sun with questions or comments about its JavaBeans Bridge for ActiveX
    bridge-comments@java.sun.com
  • Learn more about COM and ActiveX http://www.microsoft.com/com/