在启动JAVA应用程序时就算设置了classpath变量,也经常会报找不到类的错误。如果把所有jar包都加入到-cp参数中,就不会提示这个错误了。于是写一个启动脚本,告别ClassNotFoundException。
下面是WIN版批处理内容:startServer.bat
@echo off set CURR_DIR=c:\ippush cd /D %CURR_DIR%
set JAVA_HOME=%CURR_DIR%\jdk1.6.0_03
set PATH=%JAVA_HOME%\bin;%PATH%
rem 设置变量为延迟加载 setlocal=EnableDelayedExpansion set CLASSPATH=.;%JAVA_HOME%\lib;%JAVA_HOME%\jre\lib for %%j in (lib\*.jar) DO ( echo %%j set CLASSPATH=!CLASSPATH!;%CURR_DIR%\%%j echo %CLASSPATH% ) echo %CLASSPATH%
rem set JVM_ARGS="-Xms:512m -XX:MinPermSize=128m" rem echo JVM_ARGS=$JVM_ARGS
@echo on java -cp %CLASSPATH%;ippush-preresearch.jar org.jboss.netty.example.discard.IppushSimpleSocketClient
|
下面是LINUX版shell脚本:
#!/bin/sh
export CURR_DIR=/home/gegw/ippush/ cd $CURR_DIR export JAVA_HOME=/usr/java/jdk1.6.0_18 #echo JAVA_HOME=$JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH #echo PATH=$PATH
java -version
export CLASSPATH=$CURR_DIR/lib:$CURR_DIR:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
for jarfile in `ls $CURR_DIR/lib/*.jar` do export CLASSPATH=$CLASSPATH:$jarfile done
#echo CLASSPATH=$CLASSPATH
JVM_ARGS="-Xms:512m -XX:MinPermSize=128m" echo JVM_ARGS=$JVM_ARGS
ulimit -n 400000
echo "" > nohup.out
#java org.jboss.netty.bootstrap.Bootstrap nohup $JAVA_HOME/bin/java -cp $CLASSPATH:ippush-preresearch.jar com.leadtone.gegw.ippush.server.ServerStarter & |
如果你想让你的bat 在后台运行,可以使用以下文件:vbscript.vbs
set ws=wscript.createobject("wscript.shell") ws.run "startServer.bat /start",0
|
阅读(7201) | 评论(0) | 转发(0) |