bat执行java的问题
原本项目是用SSH在TOMCAT下运行的,现在要增加一个批量导入EXCEL文件的功能,我写了几个导入类,打算用BAT使其能够执行
问题:我在classpath中设置的包好像没有引入进来,此BAT文件是要放在tomcat的bin目录里的
bat内容如下:
Java code
@echo off
title 导入EXCEL文件
echo 开始载入类文件及包...
set curDir=%cd%
cd ..
set tomcatDir=%cd%
cd %curDir%
set base=%tomcatDir%\webapps\ROOT\WEB-INF
set class=%base%\classes
set lib=%base%\lib
set class_path=%CLASSPATH%;%class%;%lib%
echo %class_path%
rem *******************************************
rem 在此处设置要导入文件所在文件夹
set lidaDir="C:\lida"
set haiwanDir="C:\haiwan"
rem *******************************************
if not %lidaDir%=="" (call :importData lida %lidaDir%)
if not %haiwanDir%=="" (call :importData haiwan %haiwanDir%)
pause
rem ----------------导入数据子程序
:importData
@echo off
if "%2"=="" goto :eof
pushd %class%
for /r %2 %%i in (*.xls) do (
echo %%~fi %cd%
if "%1"=="lida" (
java -classpath %class_path% com.***.cms.excel.LiDaImportExcel %%~fi
)
if "%1"=="haiwan" (
java -classpath %class_path% com.***.cms.excel.HaiWanImportExcel %%~fi
)
)
popd
goto :eof
报错信息如下:
开始载入类文件及包...
.;C:\Java\jdk1.6.0_14\lib\dt.jar;C:\Java\jdk1.6.0_14\lib\tools.jar;D:\tomcat6[20
100729]\webapps\ROOT\WEB-INF\classes;D:\tomcat6[20100729]\webapps\ROOT\WEB-INF\l
ib
C:\lida\利达报警——3教.xls D:\tomcat6[20100729]\webapps\ROOT\WEB-INF\classes
Exception in thread "main"
java.lang.NoClassDefFoundError: org/hibernate/criteri
on/Criterion
Caused by: java.lang.ClassNotFoundException: org.hibernate.criterion.Criterion
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: com.hikvision.cms.excel.LiDaImportExcel. Program
will exit.
C:\lida\利达报警——活动中心.xls D:\tomcat6[20100729]\webapps\ROOT\WEB-INF\class
es
Exception in thread "main" java.lang.
NoClassDefFoundError: org/hibernate/criteri
on/Criterion
Caused by:
java.lang.ClassNotFoundException: org.hibernate.criterion.Criterion
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: com.hikvision.cms.excel.LiDaImportExcel. Program
will exit.
C:\lida\利达报警——图书馆.xls D:\tomcat6[20100729]\webapps\ROOT\WEB-INF\classes
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/criteri
on/Criterion
Caused by: java.lang.
ClassNotFoundException: org.hibernate.criterion.Criterion
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)