Java Spring Batch - 从jar执行

时间:2012-05-02 11:06:14

标签: java spring spring-batch

我创建了一个弹簧批处理项目。它作为Java应用程序完美执行。之后我使用maven build创建了一个jar文件。但是当我尝试运行jar文件时,抛出了以下异常:

=================================================================================
Exception in thread "main" org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 142 in XML document from class path resource [SICBatchFile.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'job'.
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396)

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'job'.
    at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
    ... 14 more

=================================================================================

它正在通过邮件课程。但是当读取xml时,它会抛出此异常。下面是xml部分:

  <beans:beans 
        xmlns="ht tp: / /www.springframework.org/schema/batch" 
        xmlns:beans="ht tp: / /www.springframework.org/schema/beans" 
        xmlns:aop="ht tp: / /www.springframework.org/schema/aop"
        xmlns:tx="ht tp: / /www.springframework.org/schema/tx" xmlns:p="ht tp: / /www.springframework.org/schema/p"
        xmlns:xsi="ht tp :/ /www.w3.org/2001/XMLSchema-instance" xmlns:util="ht tp: / /www.springframework.org/schema/util"
        xsi:schemaLocation="ht tp: / /www.springframework.org/schema/beans  ht tp: / /www.springframework.org/schema/beans/spring-beans-2.0.xsd
        ht tp: / /www.springframework.org/schema/batch  ht tp: / /www.springframework.org/schema/batch/spring-batch-2.0.xsd
        ht tp: / /www.springframework.org/schema/aop  ht tp: / /www.springframework.org/schema/aop/spring-aop-2.0.xsd
        ht tp: / /www.springframework.org/schema/tx 
        ht tp: / /www.springframework.org/schema/tx/spring-tx-2.0.xsd">

     <job id="sicProcessorJob" job-repository="jobRepository">
        <step id="step1">
        <tasklet transaction-manager="jobRepository-transactionManager">
            <chunk reader="sicFileItemReader" processor="sicProcessor"
                writer="sicFileItemWriter" commit-interval="3">
        <streams>
            <stream ref="sicFileItemWriter1"/>
            <stream ref="sicFileItemWriter2" />
          </streams>
        </chunk>    
    </tasklet>
    </step>
    <listeners>
      <listener ref="jobListener" />
    </listeners>
  </job>

IDE:Eclipse

1 个答案:

答案 0 :(得分:0)

  

之后我使用maven build创建了一个jar文件。但是当我努力的时候   运行jar文件

如果你刚刚创建了一个简单的jar文件,那么它无法工作,应用程序需要所有的库(spring,commons等)。

你可以

  • 设置classpath或使用manifest
  • 对其进行配置
  • 使用maven创建(参见stackoverflow answer
    • 可执行文件all-in-one.jar
    • 您需要的所有目录结构,包括设置正确类路径的.bat / .sh