1 安装与维护应用程序
Java应用程序有很多种,这里只讨论最普通的两种:被打包成一系列.class文件的应用程序和单一的zip形式的应用程序。下面我讨论的是通过手工安装一个应用程序的基本方法和步骤。我以一个简单的时钟应用程序Clock为例进行讲解。
1.1. 准备工作
l 为应用程序创建目录
l 将文件拷贝到创建的目录下
windows xcopy c:originaldirectory*.class c:destinationdirectory/s
unix cp -r /original/directory /destination/directory
|
1.2. 创建应用程序描述文件或批处理文件
经常地,用户需要将应用程序的运行自动化,这样就不需要每次都通过命令行输入java Clock。而且,可能有些windows用户还需要为他们的JAVA应用程序设置一个快捷方式。
1.2.1. Unix下的应用程序描述文件
我们以Solaris2.4下的Korn Shell为例。描述创建封装脚本的方法,在其它unix或shell环境下,只需要将这个脚本进行相应的少量修改就可以了。
下面是这个封装的脚本:
########Clock Script#################
#Add the applications directory to the CLASSPATH
#set to the directory you have placed the application
#Note, I insert the application directory first to avoid
#having classes from other applications getting called first
CLASSPATH=/destination/directory/ : $ CLASSPATH
#Set the location in which you hold java.
#This directory is probably the same as below
#If you have java in your global path, this line is not really necessory
Java_Home=/optl/java/bin/java
#Specify the name of the application.
#Important: Remember this is the name of the class, not the file
App=Clock
#Now run the actual program.
#If you have any additional parameters which you need to
#pass to the application, you can add them here.
$ Java_Home $ App
########Clock Script#################
完成封装脚本的输入之后,要将该脚本设置为当前用户可执行的,在控制终端输入:
$ chmod u+x Clock
|
下面测试该脚本是否可执行:
1.2.2. Windows下的应用程序批处理文件
Windows9x/Windows NT下这种应用程序的批处理文件是基本相同的,下面是这种批处理文件的清单:
Rem #########Clock.bat#############
Rem add the location where java.exe is located. If it
Rem is already in your path, don‘t add this line.
Rem change c:javain to the directory you have
Rem installed for the JDK.
Set PATH=%PATH%; c:javain
Rem Set this line to the directory where your new
Rem application is located.
Set CLASSPATH=c:appdir;%CLASSPATH%
Rem Run the actual application, change the applClass to be
Rem the correct class for the application you are installed
javaw applClass
Rem #########Clock.bat#############
|
注:
1、 如果用户应用程序不使用Windows环境,或用户需要看到System.out的输出信息,则应该用java替换javaw;
2、 如果用户应用程序不能运行,并显示类似于"Can‘t find class classname"这样的错误,用户首先要检查.zip文件所在的目录是否包含在CLASSPATH变量指定的那些目录中;其次,需要检查CLASSPATH变量中的字节数是否超过128个字符的最大限制。
注:我这里不讲JAVA小应用程序的发布方法,有兴趣的可以自己去学习。
(to be continue)
下节:基础篇之JAVA预定义包
如果您对本文有任何疑问或者建议,请到讨论区发表您的意见:
>>
论坛入口 <<
上一篇:
JAVA系列讲座2(基础篇之面向对象编程)
下一篇:
JAVA系列讲座4(基础篇之JDK1.3预定义包)
【文章评论】
【收藏本文】
【推荐好友】
【打印本文】
【我要投稿】 【论坛讨论】