RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Hosting .NET Controls in Java : Page 4

Using JNI and some COM interop magic, you can host .NET Windows controls directly in your Java applications.

Deploying and Running the Solution
Now that you've completed the code, you must deploy and test it in a production environment. The Java Runtime Environment (JRE) and the .NET Framework are required, of course, as well as the C/C++ runtime against which your JNI library was linked.

You must register the .NET assembly so that the path to the assembly can be resolved, or installed the assembly into the GAC. This procedure was discussed earlier in the section "Designing the .NET Control.".

Install the JNI library into a directory listed in the target machine's PATH environment variable. If you prefer to keep all the application files together in a single directory, you should either add the current working directory (represented by ".") or your application installation directory to the PATH environment variable, or change the lookup paths in the command line shown below used to start the Java application:

   java.exe -Djava.library.path=".;%PATH%" -classpath 
      .;%CLASSPATH% App
The command line ensures that the current working directory is included in the search path for any native libraries required by the JVM. Adding the current working directory to the CLASSPATH also ensures that the the JVM can find the Java application class files. See the Sun Java Web site for more information about deploying and executing Java classes.

Setting up your C/C++ project correctly allows you to compile and debug your native C/C++ code and your .NET code in whatever language you use. The sample project is configured to run the Java application using the command line above. You could instead use the jdb.exe application to debug the Java application at the same time.

When you have completed your testing plan, you should recompile your entire source in a release build and deploy the solution in the same way described above.

Although the process to host .NET controls in Java isn't trivial, being able to use the rich user interfaces and technologies in .NET within your Java application is advantageous. You can reuse your .NET controls in both .NET and Java applications and can potentially reduce the development time of producing and maintaining separate class libraries in different languages.

Heath Stewart is a Microsoft MVP, and the Director of Technology and a software architect at Proplanner, a .NET-centric development company in Iowa. He has been programming professionally using several different languages since the early 1990's and has written many articles for development communities such as CodeProject. Reach him by e-mail here.
Email AuthorEmail Author
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date