从命令提示符运行批处理文件获取错误

时间:2014-01-23 07:29:52

标签: java batch-file

您好我有一个批处理文件,它基本上通过运行作业来更新数据库中的某些表。

这是一个批处理文件代码:

set CLASSPATH=C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\selenium-server-standalone-2.32.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\jsoup-1.7.2.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\xstream-1.1.3.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\XmlSchema-1.4.7.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-transport-http-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\log4j-1.2.17.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\mysql-connector-java-5.1.13.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\httpclient-4.1.2.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\httpcore-4.1.2.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\commons-httpclient-3.0.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\gson-1.6.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\lucene-core-3.3.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-adb-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axiom-api-1.2.12.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-kernel-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\wsdl4j-1.6.2.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\XmlSchema-1.4.7.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axiom-impl-1.2.12.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\neethi-3.0.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\freemarker.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\smtp.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-transport-local-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-transport-http-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\mailapi.jar;
C:\ProjectWorkSpace\myProject\web\WEB-INF\classes;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-context-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-core-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-beans-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-asm-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-aop-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-tx-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\aopalliance-1.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-expression-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-orm-3.1.1.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\transactions-jdbc-3.8.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\transactions-osgi-3.8.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\hibernate-3.2.1.ga.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\hibernate-jpa-2.0-api-1.0.1.Final.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\hibernate-annotations-3.2.0.ga.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\jboss-transaction-api_1.1_spec-1.0.0.Final.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\spring-jdbc-3.1.0.RELEASE.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\dom4j-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\transactions-hibernate3-3.8.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\gdata-core-1.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\xstream-1.1.3.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\commons-lang-2.3.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\xmlunit-1.5.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\log4j-1.2.17.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\axis2-transport-http-1.6.1.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\mailapi.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\antlr-2.7.7.jar;
C:\ProjectWorkSpace\myProject\web\WEB-INF\classes;

java -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m com.myProject.batch.PropertyRatesUpdaterBatchJob

我正在尝试从命令提示符运行批处理文件,但我收到错误,如

C:\ProjectWorkSpace\myProject\tools>C:\ProjectWorkSpace\myProject\web\WEB-INF\classes;
'C:\ProjectWorkSpace\myProject\web\WEB-INF\classes' is not recognized as an internal    or     external command,
 operable program or batch file.

,最后我得到的第二个错误

Exception in thread "main" java.lang.NoClassDefFoundError: com/myProject/batch    /PropertyRatesUpdaterBatchJob
Caused by: java.lang.ClassNotFoundException:    com.myProject.batch.PropertyRatesUpdaterBatchJob
    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:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)

我无法运行批处理文件。 任何人都可以帮助我如何运行相同的错误和错误。

嗨,这是我的新批处理文件:

    set CLASSPATH=C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\selenium-server-standalone-2.32.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\jsoup-1.7.2.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\xstream-1.1.3.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\XmlSchema-1.4.7.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-transport-http-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\log4j-1.2.17.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\mysql-connector-java-5.1.13.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\httpclient-4.1.2.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\httpcore-4.1.2.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\commons-httpclient-3.0.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\gson-1.6.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\lucene-core-3.3.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-adb-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axiom-api-1.2.12.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-kernel-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\wsdl4j-1.6.2.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\XmlSchema-1.4.7.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axiom-impl-1.2.12.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\neethi-3.0.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\freemarker.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\smtp.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-transport-local-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-transport-http-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\mailapi.jar;C:\ProjectWorkSpace\zaranga\WEB-INF\classes;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-context-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-core-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-beans-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-asm-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-aop-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-tx-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\aopalliance-1.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-expression-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-orm-3.1.1.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\transactions-jdbc-3.8.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\transactions-osgi-3.8.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\hibernate-3.2.1.ga.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\hibernate-jpa-2.0-api-1.0.1.Final.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\hibernate-annotations-3.2.0.ga.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\jboss-transaction-api_1.1_spec-1.0.0.Final.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\spring-jdbc-3.1.0.RELEASE.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\dom4j-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\transactions-hibernate3-3.8.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\gdata-core-1.0.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\xstream-1.1.3.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\commons-lang-2.3.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\xmlunit-1.5.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\log4j-1.2.17.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\axis2-transport-http-1.6.1.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\mailapi.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\lib\antlr-2.7.7.jar;C:\ProjectWorkSpace\zaranga\build\zaranga\WEB-INF\classes

java -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m com.zaranga.batch.PropertyRatesUpdaterBatchJob

现在我收到一个新的错误log4j as 错误是:

No org.slf4j.impl.StaticLoggerBinder found in ClassPath, trying with log4j...

任何帮助都会受到极大关注。

1 个答案:

答案 0 :(得分:2)

我假设

set CLASSPATH=C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\selenium-server-standalone-2.32.0.jar;
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\jsoup-1.7.2.jar;

您还希望将jsoup-1.7.2.jar;添加到CLASSPATH变量,但您不能只是将命令扩展到多行。

如果你想在多行上写这个,那么每行(当然最后一行除外)必须结束所谓的“行继续符”,告诉Windows该命令(在您的情况SET)尚未完成,即使该行已经完成。 Windows中的此字符为^(与Linux / Unix shell脚本中的\相当)

所以你需要的是:

set CLASSPATH=C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\selenium-server-standalone-2.32.0.jar; ^
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\jsoup-1.7.2.jar; ^
C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\xstream-1.1.3.jar; ^
.... ^
.... ^
C:\ProjectWorkSpace\myProject\web\WEB-INF\classes;

java -Xmx1024m -XX:MaxPermSize=512m -XX:ReservedCodeCacheSize=128m com.myProject.batch.PropertyRatesUpdaterBatchJob

(顺便说一句:你的名单中有C:\ProjectWorkSpace\myProject\web\WEB-INF\classes两次)

您必须确保在^之后存在空格,否则无效。

顺便说一下:你不应再使用CLASSPATH变量了。最好使用-cp(或-classpath命令的java参数显式定义类路径。

在最近的(最新)Java版Windows版本中,您无需在classpath变量中指定每个元素。

来自http://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html

  

作为一种特殊的方便,包含基本名称*的类路径元素被认为等同于指定扩展名为.jar或.JAR 的目录中所有文件的列表。 p>

所以你可以摆脱所有的线条,只需使用:

java -cp C:\ProjectWorkSpace\myProject\build\myProject\WEB-INF\lib\*;C:\ProjectWorkSpace\myProject\web\WEB-INF\classes  com.myProject.batch.PropertyRatesUpdaterBatchJob