- 在Unix Shell脚本里运行Java application,要确认该机器上是否安装了JRE。
- Shell脚本的内容说明如下:
- 设定CLASSPATH
- LIB_PATH=${BATCH_HOME}/lib
- export CLASSPATH=$CLASSPATH:.
- CLASSPATH=${CLASSPATH}:$LIB_PATH/activation-1.1.jar
- …
- 上面设定CLASSPATH里的jar文件要包含运行Iava application需要的所有第三方Java class,如果设定的不充分会在运行Java application的过程中抛出java.lang.ClassNotFoundException
- 使用下面的命令运行Java class的main方法
java jp.co.sony.impacts.epi.batch.BatchMain $*
$* 表示传递给Java main方法的参数,任意多个
- 使用 $? 取得Java application运行结果的Exit code
Java application运行结果的Exit code就是Java source里的代码 System.exit(int);里的整型参数的值
例子程序:
#JAVA配置(FW)
LIB_PATH=${BATCH_HOME}/lib
export CLASSPATH=$CLASSPATH:.
CLASSPATH=${CLASSPATH}:$LIB_PATH/activation-1.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/annogen-0.1.0.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/aopalliance-1.0.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axiom-api-1.2.7.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axiom-dom-1.2.7.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axiom-impl-1.2.7.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-adb-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-clustering-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-corba-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-fastinfoset-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-java2wsdl-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-jaxbri-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-jaxws-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-jaxws-api-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-jibx-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-json-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-jws-api-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-kernel-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-metadata-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-mtompolicy-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-saaj-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-saaj-api-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/axis2-xmlbeans-1.4.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/backport-util-concurrent-3.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-beanutils-1.8.0.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-codec-1.3.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-collections-3.2.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-digester-1.8.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-fileupload-1.2.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-httpclient-3.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-io-1.4.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-lang-2.3.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-logging-1.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/commons-validator-1.3.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/geronimo-stax-api_1.0_spec-1.0.1.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/jakarta-oro-2.0.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/javassist-3.4.ga.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/jdom.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/log4j-1.2.13.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/mail-1.4.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/neethi-2.0.4.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/ognl-2.6.9-patch-20070908.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/ojdbc14.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/s2-framework-2.4.34.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/woden-api-1.0M8.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/woden-impl-dom-1.0M8.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/wsdl4j-1.6.2.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/wstx-asl-3.2.4.jar
CLASSPATH=${CLASSPATH}:$LIB_PATH/XmlSchema-1.4.2.jar
CLASSPATH=${CLASSPATH}:${BATCH_HOME}/resources
export LOG4J_CONFIG_PATH=${BATCH_HOME}/resources/conf/epi/log4j.xml
JAVA_RUN()
{
java epi.batch.BatchMain $*
if [ $? -ne 0 ]
then
return 1
else
return 0
fi
}