您的位置:首页 >> 编程开发 >> Java >> J2EE >> 正文
J2EE RSS
 

Creating a Custom Launcher @ JDJ

http://www.rdxx.com 05年08月10日 20:22 Java频道 我要投稿

关键词: JDJ , ATI

The most frustrating and error-prone aspect of Java for the average useris starting a Java program. The monumental confusion of batch files,scripts, and command-line cut-and-paste that's necessary to start a Javaprogram using the default launcher is an ongoing problem area even forveteran developers.

This article shows how you can wipe away the whole mess and easily writecustom launchers for your applications. A custom launcher makes startup assimple as point-and-click and can be the difference between a programappearing professional or appearing unusable. The specifics on makinglaunchers for all the major platforms are also covered.

A long-time barrier to user acceptance of Java has been the confusingand unfriendly default launcher. It requires long strings of command-linearguments before it will start a Java program. Both users and softwaredevelopers constantly receive the java.lang.NoClassDefFound exception andother errors. Sun's noble response to this problem is to provide a publicAPI, the invocation interface, that can be used to start the JVM andaccompanying Java program. Although a few commercial applications use thisAPI, it's woefully underutilized overall. I'll show how easy it is to createa custom launcher and provide templates that you can use to automate startupof your Java programs. There's even a generic configurable launcher that'sready to run, no compilation necessary.

I focus on the three major desktop platforms: Windows, Mac OS, and Unix.Each platform has its own quirks, but using a custom launcher bringsbenefits that are common to all three, such as:

  • Program startup is easier and more reliable.
  • Software identification and branding are better.
  • Greater customization and VM control is possible.
Given that a commercial-quality launcher requires only about 200 linesof code and templates are provided, there's no reason you can't get startedtoday.

How Java Programs Are Launched
The complexity of launching a Java program is largely due to Java beingan interpreted language. This makes startup and shutdown a multistepprocedure (see Figure 1).

As the figure suggests, any native executable can start a Java program.A Java launcher is a native executable dedicated solely to starting Javaprograms. The most commonly used launchers are the ones Sun supplies in the/bin directory of the Java runtime distribution. In the case of the Windowsplatform, these programs are "java.exe" and "javaw.exe". The former openstwo windows: a console that receives System.out/err and output from thelauncher and the Java window itself. The latter, a windowless launcher,opens only the Java window. On J2SE/EE platforms the virtual machine isimplemented as a dynamic link library that's also in the /bin directory. OnWindows it's called "java.dll", on Unix "java.so". Loading the VM equates toloading this DLL.

Users specify options to the VM in two ways. They can put the options onthe command line to the launcher and/or define environment variables withthe desired settings. One of the options, the startup class, can only bespecified on the command line. This bifurcation of the executionconfiguration is a common source of confusion that can be eliminated byusing a custom launcher.

9 7 3 1 2 3 4 5 4 8 :


 
 
标签: JDJ , ATI 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站