1

I have created an executable JAR for a Spring project through Eclipse.

It worked as I expected on my system, but when I am trying to execute the same JAR on another system, it does not work. It throws an exception like:

Exception-->
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from
 relative location [applicationContext-DAO.xml]
Offending resource: class path resource [resources/applicationContext.xml]; nested exception is org.springframework.beans.factory.xml.X
mlBeanDefinitionStoreException: Line 6 in XML document from class path resource [resources/applicationContext-DAO.xml] is invalid; nest
ed exception is org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 336; cvc-elt.1: Cannot find the declaration of element 'bea
ns'.
        at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
        at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:76)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinition
DocumentReader.java:271)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseDefaultElement(DefaultBeanDefinitionDocumentR
eader.java:196)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocument
Reader.java:181)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.doRegisterBeanDefinitions(DefaultBeanDefinitionDoc
umentReader.java:140)
        at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocum
entReader.java:111)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302)
        at com.nextenders.server.ApplicationContext.initContextFile(ApplicationContext.java:88)
        at com.nextenders.server.ApplicationContext.<init>(ApplicationContext.java:60)
        at com.nextenders.server.ApplicationContext.getInstance(ApplicationContext.java:45)
        at com.nextenders.common.DaoReceiver.processRequest(DaoReceiver.java:49)
        at com.nextenders.common.DaoHandler.handleRequest(DaoHandler.java:12)
        at com.nextenders.facadeimplementation.facade.UtilityFacade.main(UtilityFacade.java:625)
Caused by: org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 6 in XML document from class path resource [reso
urces/applicationContext-DAO.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 336; 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.xml.DefaultBeanDefinitionDocumentReader.importBeanDefinitionResource(DefaultBeanDefinition
DocumentReader.java:255)
        ... 14 more
Caused by: org.xml.sax.SAXParseException; lineNumber: 6; columnNumber: 336; cvc-elt.1: Cannot find the declaration of element 'beans'.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.handleStartElement(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.xs.XMLSchemaValidator.startElement(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl$NSContentDriver.scanRootElementHook(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source)
        at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
        at com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(Unknown Source)
        at com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(Unknown Source)
        at org.springframework.beans.factory.xml.DefaultDocumentLoader.loadDocument(DefaultDocumentLoader.java:75)
        at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:388)
        ... 17 more

C:\programforforkdocument>

I am not getting what is the issue? I have one doubt like is it something related to the path? Might my system be getting the proper path while executing because it is created from my system?

Update: New Error:

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 9 in
 XML document from class path resource [resources/applicationContext.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.

I am using spring--3.2.0.RC2.jar and my schema entry like

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans  http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd">
DaveyDaveDave
  • 9,821
  • 11
  • 64
  • 77
bNd
  • 7,512
  • 7
  • 39
  • 72

3 Answers3

1

Refering to your update: See this solution:

Create runnable jar with maven 3.1 using maven-dependency-plugin doesn't create runnable jar

The Problem seems to be with internal spring files which haven been overwritten in assembly phase. Which maven plugin do you use for assembly? Its seems that you have to use the maven-shade-plugin when building jars with spring framework which merges spring-handlers and spring-schemas. See solution of question.

Community
  • 1
  • 1
Dennis Ahaus
  • 969
  • 1
  • 8
  • 17
0

It looks to me like you might be missing a library. I am guessing the one that has the spring-beans.dtd file in it.

CodeChimp
  • 8,016
  • 5
  • 41
  • 79
  • applicationContext.xml is an XML file. The SAXParserException is indicating that the XML failed validation, hence the text "Cannot find the declaration of element 'beans'", which is indicating that the SAX Parser could not file the definition of the element called 'beans'. Those Spring XML elements are defined in spring-beans-3.0.dtd, which is a Document Type Definition defining the XML contract for parsers to use to interpret the XML files. That file is usually in the spring.jar, which seems to indicate it's not in your classpath. – CodeChimp May 09 '13 at 11:22
  • This may also help (found after about 30sec of Google'ing): http://stackoverflow.com/questions/13814321/cannot-find-the-declaration-of-element-beans – CodeChimp May 09 '13 at 11:25
  • I have done change according to it but it shows me new error. I am updated my question. any idea? – bNd May 09 '13 at 13:02
  • You are having a disconnect between the context XML's assigned DTD and the one that is being found (or completely not found). – CodeChimp May 09 '13 at 17:20
0

Add spring-beans jar to classpath

jmj
  • 237,923
  • 42
  • 401
  • 438
  • It is already there. As I mention here. it is working on one system where it is created!!. but not another. any idea? – bNd May 10 '13 at 04:58
  • You might have some junk characters in xml file, copy it to notepad and see if it shows some weird characters – jmj May 10 '13 at 05:18