4

Eclipse を使用して、Spring-Batch アプリケーションを作成しました。Eclipse でプログラムを実行すると、問題なく実行されます。しかし、ant を使用して作成された jar ファイルを生成して実行しようとすると、この醜いスタック トレースが表示されます。

2012-Dec-27 11:10:30,880 1141 [main][] エラー (CommandLineJobRunner.java:355): ジョブがエラーで終了しました: クラスパス リソース [launch-context.xml] からの XML ドキュメントの 12 行目が無効です。ネストされた例外は org.xml.sax.SAXParseException: cvc-elt.1: 要素「beans」の宣言が見つかりません。org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: クラスパス リソース [launch-context.xml] からの XML ドキュメントの 12 行目が無効です。ネストされた例外は org.xml.sax.SAXParseException: cvc-elt.1: 要素「beans」の宣言が見つかりません。org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) で org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) で org.springframework.beans.factory.xml.XmlBeanDefinitionReader.java:334 springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) com.my.path.invoker.JobTest.main(JobTest.java:25) 原因: org.xml.sax.SAXParseException: cvc-elt.1: 要素「beans」の宣言が見つかりません。com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) で com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131) でcom.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384) で com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318) でcom.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1916) com.sun.org.apache.xerces. . 16以上

基本的に、11 行目で要素 Bean の宣言が見つからないということです。これが私の起動コンテキストです。

<?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"        
        xmlns:batch="http://www.springframework.org/schema/batch"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:jdbc="http://www.springframework.org/schema/jdbc"
        xsi:schemaLocation="
            http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
            http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

        <bean id="placeholderConfig"
            class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="locations">
                <list>
                    <value>file:batch.properties</value>
                    <value>file:application.properties</value>
                </list>
            </property>
        </bean>


        <context:component-scan base-package="com.my.path" />

        <import resource="classpath:/META-INF/spring/batch-context.xml" />
        <import resource="classpath:/META-INF/spring/module-context.xml" />


    </beans>

そしてjarを生成した私のbuild.xml。

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- WARNING: Eclipse auto-generated file.
              Any modifications will be overwritten.
              To include a user specific buildfile here, simply create one in the same
              directory with the processing instruction <?eclipse.ant.import?>
              as the first entry and export the buildfile again. -->
<project basedir="." default="jar" name="ERS2Utilities">
    <property environment="env"/>
    <property name="debuglevel" value="source,lines,vars"/>
    <property name="target" value="1.6"/>
    <property name="source" value="1.6"/>
    <path id="CLASSPATH">
        <pathelement location="target/classes"/>
        <pathelement location="target/test-classes"/>
        <!-- 
        <pathelement location="src/main/resources/lib/antlr-2.7.7.jar"/>
        <pathelement location="src/main/resources/lib/antlr-runtime-3.2.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.instrument.tomcat-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.jms-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.js-2.1.1.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.web-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.web.portlet-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.web.servlet-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.web.struts-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.webflow-2.1.1.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/slf4j-api-1.6.1.jar"/>
        <pathelement location="src/main/resources/lib/slf4j-api.jar"/>
        <pathelement location="src/main/resources/lib/slf4j-log4j12-1.6.1.jar"/>
        <pathelement location="src/main/resources/lib/commons-digester.jar"/>
         -->
        <pathelement location="src/main/resources/lib/com.springsource.org.aopalliance-1.0.0.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.aop-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.asm-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.aspects-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.beans-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.binding-2.1.1.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.context-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.context.support-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.core-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.expression-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.instrument-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.jdbc-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.orm-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.oxm-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.test-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/org.springframework.transaction-3.0.3.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/spring-batch-infrastructure-2.1.9.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/spring-batch-core-2.1.9.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/spring-batch-test-2.1.9.RELEASE.jar"/>
        <pathelement location="src/main/resources/lib/commons-beanutils.jar"/>
        <pathelement location="src/main/resources/lib/commons-collections-3.1.jar"/>
        <pathelement location="src/main/resources/lib/commons-dbcp-1.4.jar"/>
        <pathelement location="src/main/resources/lib/commons-lang-2.6.jar"/>
        <pathelement location="src/main/resources/lib/commons-logging-1.1.1.jar"/>
        <pathelement location="src/main/resources/lib/commons-pool-1.5.4.jar"/>
        <pathelement location="src/main/resources/lib/junit-4.7.jar"/>
        <pathelement location="src/main/resources/lib/ojdbc14.jar"/>
        <pathelement location="src/main/resources/lib/log4j-1.2.16.jar"/>
        <pathelement location="src/main/resources/lib/HashUtility.jar"/>
        <pathelement location="src/main/resources/lib/commons-io-2.4.jar"/>
        <pathelement location="src/main/resources/lib/mockito-all-1.9.5.jar"/>
    </path>
    <target name="init">
        <mkdir dir="target/classes"/>
        <mkdir dir="target/test-classes"/>
        <copy includeemptydirs="false" todir="target/classes">
            <fileset dir="src/main/resources">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="target/classes">
            <fileset dir="src/main/java">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="target/test-classes">
            <fileset dir="src/test/java">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
        <copy includeemptydirs="false" todir="target/classes">
            <fileset dir="src/test/resources">
                <exclude name="**/*.java"/>
            </fileset>
        </copy>
    </target>
    <target name="clean">
        <delete dir="target/classes"/>
        <delete dir="target/test-classes"/>
    </target>



    <target depends="init" name="build-project">
        <echo message="${ant.project.name}: ${ant.file}"/>
        <javac debug="true" debuglevel="${debuglevel}" destdir="target/classes" source="${source}" target="${target}">
            <src path="src/main/resources"/>
            <classpath refid="CLASSPATH"/>
        </javac>
        <javac debug="true" debuglevel="${debuglevel}" destdir="target/classes" source="${source}" target="${target}">
            <src path="src/main/java"/>
            <classpath refid="CLASSPATH"/>
        </javac>
        <javac debug="true" debuglevel="${debuglevel}" destdir="target/test-classes" source="${source}" target="${target}">
            <src path="src/test/java"/>
            <classpath refid="CLASSPATH"/>
        </javac>
        <javac debug="true" debuglevel="${debuglevel}" destdir="target/classes" source="${source}" target="${target}">
            <src path="src/test/resources"/>
            <classpath refid="CLASSPATH"/>
        </javac>
    </target>

    <!-- <target description="compile project with Eclipse compiler" name="build-eclipse-compiler">
        <property name="build.compiler" value="org.eclipse.jdt.core.JDTCompilerAdapter"/>
        <antcall target="build"/>
    </target> -->

    <target name="JobTest">
        <java classname="com.my.path.invoker.JobTest" failonerror="true" fork="yes">
            <arg line="launch-context.xml oiaExtractorJob"/>
            <classpath refid="CLASSPATH"/>
        </java>
    </target>

    <target name="jar" depends="build-project">
        <copy todir="build/main" file="src/main/resources/log4j.xml"/>
        <copy todir="build/main" file="application.properties"/>
        <copy todir="build/main" file="batch.properties"/>
        <copy todir="build/main" file="src/main/resources/ERSUtilities.sh"/>
        <copy todir="build/main" file="src/main/resources/ERSUtilities.bat"/>

        <jar destfile="build/main/ERS2SupportingUtilities.jar">
            <fileset dir="target/classes"/>
            <restrict>
             <name name="**/*.class"/>
             <archives>
               <zips>
                 <fileset dir="./src/main/resources/lib" includes="**/*.jar"/>
               </zips>
             </archives>
            </restrict>
            <manifest>
              <attribute name="Main-Class" value="com.my.path.invoker.JobTest"/>
                <attribute name="Class-Path" value="./lib/log4j-1.2.16.jar
                                                    ./lib/org.springframework.context-3.0.3RELEASE.jar
                                                    ./lib/org.springframework.asm-3.0.3.RELEASE.jar
                                                    ./lib/junit-4.7.jar
                                                    ./lib/org.springframework.orm-3.0.3.RELEASE.jar
                                                    ./lib/org.springframework.transaction-3.0.3.RELEASE.jar
                                                    ./lib/org.springframework.aspects-3.0.3.RELEASE.jar
                                                    ./lib/commons-pool-1.5.4.jar
                                                    ./lib/org.springframework.core-3.0.3.RELEASE.jar
                                                    ./lib/commons-logging-1.1.1.jar
                                                    ./lib/HashUtility.jar
                                                    ./lib/org.springframework.expression-3.0.3.RELEASE.jar
                                                    ./lib/commons-lang-2.6.jar
                                                    ./lib/org.springframework.instrument-3.0.3.RELEASE.jar
                                                    ./lib/mockito-all-1.9.5.jar
                                                    ./lib/com.springsource.org.aopalliance-1.0.0.jar
                                                    ./lib/ojdbc14.jar
                                                    ./lib/commons-io-2.4.jar
                                                    ./lib/commons-collections-3.1.jar
                                                    ./lib/org.springframework.jdbc-3.0.3.RELEASE.jar
                                                    ./lib/spring-batch-infrastructure-2.1.9.RELEASE.jar
                                                    ./lib/org.springframework.context.support-3.0.3.RELEASE.jar
                                                    ./lib/commons-dbcp-1.4.jar
                                                    ./lib/spring-batch-test-2.1.9.RELEASE.jar
                                                    ./lib/org.springframework.beans-3.0.3.RELEASE.jar
                                                    ./lib/org.springframework.oxm-3.0.3.RELEASE.jar
                                                    ./lib/org.springframework.aop-3.0.3.RELEASE.jar
                                                    ./lib/commons-beanutils.jar
                                                    ./lib/org.springframework.binding-2.1.1.RELEASE.jar
                                                    ./lib/spring-batch-core-2.1.9.RELEASE.jar
                                                    ./lib/org.springframework.test-3.0.3.RELEASE.jar
                                                    ./launch-context.xml
                                                    ./log4j.xml"
                />
            </manifest>
        </jar>
    </target>
</project>

私はこれに3日以上費やしましたが、役に立ちませんでした。作成している xsd 参照が、使用している spring jar のバージョンと互換性があることを確認しました。

どんな助けでも大歓迎です。

編集:

同じ launch-context.xml が Eclipse で機能し、指定された ant build.xml を使用してビルドすると、このエラーがスローされます。

編集2:

すべての依存 jar を 1 つの太い jar にパッケージ化しようとしています。私はそれができないことを示唆するいくつかの投稿に出くわしました。パッケージ化された jar を参照するには、必要one-jarまたは eclipse のjarinjarloader. そうしないと、依存する jar をメインの jar の外に置いておく必要があります。これらのオプションを試して、これが本当の問題である場合は戻ってきます. その間、この編集に関する意見があれば、回答を更新してください。正しいものとしてマークします。

4

3 に答える 3

1

選択した XML エディター/バリデーターは、アプリケーション コンテキスト (起動コンテキストと呼ばれるもの) を正常に検証しますか? が有効でないため、有効でhttp://www.springframework.org/schema/batch/spring-batch-2.1.xsdはありません。

batchしかし、あなたが投稿したもの(抜粋だけですか?)は、名前空間さえ必要としません。したがって、それを削除して有効な XML に変換することができます。

于 2012-12-28T12:13:14.603 に答える
0

antスクリプトでは、Spring 3.0.3に依存関係があり、アプリケーションコンテキストでは、Spring 3.0が含まれていますが、それが問題になる可能性がありますか?

于 2012-12-28T14:03:32.827 に答える