Reputation: 4167
We have built a spring-batch application using eclipse. Whenever I execute program through eclipse, it just runs fine. But when I try to generate and run a jar file created using ant, I get this ugly stack trace.
2012-Dec-27 11:10:30,880 1141 [main][] ERROR (CommandLineJobRunner.java:355): Job Terminated in error: Line 12 in XML document from class path resource [launch-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'. org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 12 in XML document from class path resource [launch-context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'. at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:396) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:212) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:126) at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:92) at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:130) at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:467) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:397) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:139) at org.springframework.context.support.ClassPathXmlApplicationContext.(ClassPathXmlApplicationContext.java:83) at org.springframework.batch.core.launch.support.CommandLineJobRunner.start(CommandLineJobRunner.java:282) at org.springframework.batch.core.launch.support.CommandLineJobRunner.main(CommandLineJobRunner.java:574) at com.my.path.invoker.JobTest.main(JobTest.java:25) Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(XMLSchemaValidator.java:1916) at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(XMLSchemaValidator.java:705) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:400) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(XMLNSDocumentScannerImpl.java:626) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:3103) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(XMLDocumentScannerImpl.java:922) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:648) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:140) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:511) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:808) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:737) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:119) at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:235) at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75) at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388) ... 16 more
Its basically saying that at line 11 it cannot find declaration for element beans. Here is my launch-context.
<?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>
and my build.xml that generated the jar.
<?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>
I have spent more than a 3 days on this with no avail. I have made sure the xsd references I am making are compatible with the version of spring jar I am using.
Any help would be greatly appreciated.
The same launch-context.xml works in eclipse, its when built through the given ant build.xml that it throws this error.
I am trying to package all the dependent jars into one, fat jar. I've come across few posts which suggests that I can't do that. To reference packaged jar, I either need one-jar
or eclipse's jarinjarloader
. Otherwise I will have to keep dependent jars outside my main jar. I will try these options and get back if this is the real issue. Meanwhile, if any of you have any inputs on this edit, please update your answers, I will mark them as correct.
Upvotes: 4
Views: 5449
Reputation: 3868
If your execution server's firewall blocks access to outside internet (which is generally a good thing), then you'll need to use spring.handlers and spring.schemas to help the application parse your context files.
This will reference the schemas present in your framework libraries rather than trying to pull them from the internet.
/META-INF/spring.handlers
http\://www.springframework.org/schema/batch=org.springframework.batch.core.configuration.xml.CoreNamespaceHandler
http\://www.springframework.org/schema/context=org.springframework.context.config.ContextNamespaceHandler
http\://www.springframework.org/schema/jdbc=org.springframework.jdbc.config.JdbcNamespaceHandler
/META-INF/spring.schemas
http\://www.springframework.org/schema/beans/spring-beans-3.0.xsd=org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http\://www.springframework.org/schema/context/spring-context-3.0.xsd=org/springframework/context/config/spring-context-3.0.xsd
http\://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd=org/springframework/jdbc/config/spring-jdbc-3.0.xsd
http\://www.springframework.org/schema/batch/spring-batch-2.1.xsd=org/springframework/batch/core/configuration/xml/spring-batch-2.1.xsd
Upvotes: 0
Reputation: 1841
In the ant script you have a dependency for spring 3.0.3, and in the application context you include spring 3.0, might that be the issue?
Upvotes: 0
Reputation: 23535
Does the XML editor/validator of your choice successfully validate your application context (the one you call launch-context)? It's not valid because http://www.springframework.org/schema/batch/spring-batch-2.1.xsd
is not valid.
However, what you posted (is it only an excerpt?) doesn't even need the batch
namespace. Hence, you can remove it thereby turning it into valid XML.
Upvotes: 1