Link to home
Start Free TrialLog in
Avatar of Jay Roy
Jay RoyFlag for United States of America

asked on

spring on unix box

hi guys


i have my spring-config.xml which goes like

 
<?xml version="1.0" encoding="UTF-8"?>

<beans:beans xmlns="http://www.springframework.org/schema/batch"

                xmlns:beans="http://www.springframework.org/schema/beans" xmlns:aop="http://www.springframework.org/schema/aop"

                xmlns:tx="http://www.springframework.org/schema/tx" xmlns:p="http://www.springframework.org/schema/p"

                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util"

                xmlns:batch="http://www.springframework.org/schema/batch"

                xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

                http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch-2.1.xsd

                http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

                http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

                http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd

                                http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd">

 

..<my beans...>

</beans:beans>

 

Open in new window



I am using maven set up to load the libraries
The application runs fine from windows systems
however when i create a jar and try to run it from my unix box it throws error
 

in unix this is what ia m doing

$java -Denv=dev -jar $HOME/Customer.jar param1

 
Customer jar has
public class CustomerMain{

...

public static void main(String args[]) {                     

ApplicationContext applicationContext = new    ClassPathXmlApplicationContext("spring-config.xml");

 
...

}
}

Open in new window



 The error is
org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 12 in XML document from class path resource [spring-config.xml] is invalid; 

nested exception is org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 110; cvc-elt.1: Cannot find the declaration of element 'beans: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:174)

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:209)

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:180)

        at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:243)

 

Open in new window


 
Any idea what is going wrong ? What i am confused is it works from Windows (when i run CustomerMain.java as java application) but it fails when run from unix.

 

Any idea why that is ?

 

 

thanks
Avatar of mccarl
mccarl
Flag of Australia image

The application runs fine from windows systems
Are you running it on Windows using the exact same jar and command line that you are on the unix box?

Here's my thoughts on whats happening... On your Windows box, when you say that it is working, you are actually running it via your development environment (eg. Eclipse, Netbeans, IntelliJ, etc). And then Maven produces a JAR file of "your code" which you copy to unix and it fails to run there. The problem then is that on Unix you don't have all the other JAR's that you need, ie. Spring, and all its dependencies, and hence the error message.
Avatar of Jay Roy

ASKER

>>And then Maven produces a JAR file of "your code"

actually I export the java project as a runnable jar.
(in eclipse) right click on project --export as --runnable jar  

and in the unix box I do have a folder created called 'lib' and placed all the required jars there
and put those jars in the class path, I dont think its a problem with jars.

any other clue what could be the reason for the error on unix box?
thanks.
Can you post your CLASSPATH here then? I still think it is a case where not ALL the dependencies are satisfied.
Looks like an internal xml inconsistency. I think you need to ensure you have exactly the same Spring version on each box to ensure problem-free portability
Avatar of Jay Roy

ASKER

well in my unix script i am doing



export LIB=$HOME/lib;   #lib contains all the jars

for file in ${LIB}/*.* ; do  CLASSPATH=$CLASSPATH:$file; done




#and trying to run using

$java -Denv=dev -jar $HOME/Customer.jar param1

$java -cp $CLASSPATH -Denv=dev -jar $HOME/Customer.jar param1

but no luck

i think the jars are in classpath its some other issue.
Ah, ok, I can see another issue then. You cannot use the -jar option and set the classpath (either by -cp option or environment) at the same time. Try this...

Java -cp $CLASSPATH;$HOME/Customer.jar -Denv=dev CustomerMain param1

Note, if CustomerMain resides in a package, rather the in the default root package, you have to specify the fully qualified name above, ie. if it is in "cust.main" then you need to specify cust.main.CustomerMain in the command above.
Avatar of Jay Roy

ASKER

hm i did that but getting

...
/cust/testing/customer/Customer.jar param1
Usage: java [-options] class [args...]
           (to execute a class)
   or  java [-options] -jar jarfile [args...]
           (to execute a jar file)
where options include:
    -d32          use a 32-bit data model if available
    -d64          use a 64-bit data model if available
    -server       to select the "server" VM
                  The default VM is server,
                  because you are running on a server-class machine.


    -cp <class search path of directories and zip/jar files>
    -classpath <class search path of directories and zip/jar files>
                  A : separated list of directories, JAR archives,
                  and ZIP archives to search for class files.
    -D<name>=<value>
                  set a system property
    -verbose[:class|gc|jni]
                  enable verbose output
    -version      print product version and exit
    -version:<value>
                  require the specified version to run
    -showversion  print product version and continue
    -jre-restrict-search | -no-jre-restrict-search
                  include/exclude user private JREs in the version search
    -? -help      print this help message
    -X            print help on non-standard options
    -ea[:<packagename>...|:<classname>]
    -enableassertions[:<packagename>...|:<classname>]
                  enable assertions with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -esa | -enablesystemassertions
                  enable system assertions
    -dsa | -disablesystemassertions
                  disable system assertions
....
Avatar of Jay Roy

ASKER

and this is my command
java -cp $CLASSPATH;$HOME/Customer.jar -Denv=dev com.test.CustomerMain param1
SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Jay Roy

ASKER

changed to
>>java -cp $CLASSPATH:$HOME/Customer.jar -Denv=dev com.test.CustomerMain param1  
now it doesnt look like the main method is invoked.
What output did you get?

Please post output of

echo $CLASSPATH

Open in new window

Avatar of Jay Roy

ASKER

echo $CLASSPATH

.:/apps/com/cust/config::/apps/com/cust/lib/activation-1.1.jar:/apps/com/cust/lib/aopalliance-1.0.jar:/apps/com/cust/lib/com.jameria.ocpt.tmta-0.0.1.jar:/apps/com/cust/lib/commons-beanutils-1.8.2.jar:/apps/com/cust/lib/commons-codec-1.5.jar:/apps/com/cust/lib/commons-collections-3.2.1.jar:/apps/com/cust/lib/commons-dbcp-1.4.jar:/apps/com/cust/lib/commons-digester-2.0.jar:/apps/com/cust/lib/commons-io-2.4.jar:/apps/com/cust/lib/commons-jexl-2.0.1.jar:/apps/com/cust/lib/commons-logging-1.1.1.jar:/apps/com/cust/lib/commons-pool-1.5.4.jar:/apps/com/cust/lib/dom4j-1.6.1.jar:/apps/com/cust/lib/geronimo-stax-api_1.0_spec-1.0.jar:/apps/com/cust/lib/jcl-over-slf4j-1.7.3.jar:/apps/com/cust/lib/jettison-1.1.jar:/apps/com/cust/lib/jms-1.1.jar:/apps/com/cust/lib/jmxri-1.2.1.jar:/apps/com/cust/lib/jmxtools-1.2.1.jar:/apps/com/cust/lib/jtds-1.2.5.jar:/apps/com/cust/lib/jxls-core-1.0-RC-2.jar:/apps/com/cust/lib/jxls-reader-1.0-RC-2.jar:/apps/com/cust/lib/log4j-1.2.15.jar:/apps/com/cust/lib/mail-1.4.jar:/apps/com/cust/lib/ojdbc14-10.2.0.3.0.jar:/apps/com/cust/lib/poi-3.9.jar:/apps/com/cust/lib/poi-ooxml-3.6.jar:/apps/com/cust/lib/poi-ooxml-schemas-3.6.jar:/apps/com/cust/lib/slf4j-api-1.7.3.jar:/apps/com/cust/lib/slf4j-log4j12-1.7.4.jar:/apps/com/cust/lib/spring-aop-2.5.6.jar:/apps/com/cust/lib/spring-batch-core-2.1.9.RELEASE.jar:/apps/com/cust/lib/spring-batch-infrastructure-2.1.9.RELEASE.jar:/apps/com/cust/lib/spring-beans-3.2.2.RELEASE.jar:/apps/com/cust/lib/spring-context-3.2.2.RELEASE.jar:/apps/com/cust/lib/spring-core-3.2.2.RELEASE.jar:/apps/com/cust/lib/spring-expression-3.2.2.RELEASE.jar:/apps/com/cust/lib/spring-jdbc-3.2.2.RELEASE.jar:/apps/com/cust/lib/spring-support-2.0.8.jar:/apps/com/cust/lib/spring-tx-3.2.2.RELEASE.jar:/apps/com/cust/lib/sqljdbc4-3.0.jar:/apps/com/cust/lib/stax-api-1.0.1.jar:/apps/com/cust/lib/xml-apis-1.0.b2.jar:/apps/com/cust/lib/xmlbeans-2.3.0.jar:/apps/com/cust/lib/xpp3_min-1.1.4c.jar:/apps/com/cust/lib/xstream-1.3.jar:/apps/com/cust/config/dev/*.*::/apps/com/cust/lib/activation-1.1.jar:/apps/com/cust/lib/aopalliance-1.0.jar:/apps/com/cust/lib/com.jameria.ocpt.tmta-0.0.1.jar:/apps/com/cust/lib/commons-beanutils-1.8.2.jar:/apps/com/cust/lib/commons-codec-1.5.jar:/apps/com/cust/lib/commons-collections-3.2.1.jar:/apps/com/cust/lib/commons-dbcp-1.4.jar:/apps/com/cust/lib/commons-digester-2.0.jar:/apps/com/cust/lib/commons-io-2.4.jar:/apps/com/cust/lib/commons-jexl-2.0.1.jar:/apps/com/cust/lib/commons-logging-1.1.1.jar:/apps/com/cust/lib/commons-pool-1.5.4.jar:/apps/com/cust/lib/dom4j-1.6.1.jar:/apps/com/cust/lib/geronimo-stax-api_1.0_spec-1.0.jar:/apps/com/cust/lib/jcl-over-slf4j-1.7.3.jar:/apps/com/cust/lib/jettison-1.1.jar:/apps/com/cust/lib/jms-1.1.jar:/apps/com/cust/lib/jmxri-1.2.1.jar:/apps/com/cust/lib/jmxtools-1.2.1.jar:/apps/com/cust/lib/jtds-1.2.5.jar:/apps/com/cust/lib/jxls-core-1.0-RC-2.jar:/apps/com/cust/lib/jxls-reader-1.0-RC-2.jar:/apps/com/cust/lib/log4j-1.2.15.jar:/apps/com/cust/lib/mail-1.4.jar:/apps/com/cust/lib/ojdbc14-1
Avatar of Jay Roy

ASKER

ok this is getting printed in the logs

org.xml.sax.SAXParseException; lineNumber: 12; columnNumber: 110; schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans-3.1.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>.
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:198)
        at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.warning(ErrorHandlerWrapper.java:99)
As i mentioned above, it looks like a misconfiguration of xml:

http://www.springframework.org/schema/beans/spring-beans-3.1.xsd

doesn't exist, so won't be resolvable. Check what it should be for your version of Spring
Avatar of Jay Roy

ASKER

hmmmm strange, i see that too, but it works from windows so i am confused
Avatar of Jay Roy

ASKER

i am using spring-beans-3.2.2.RELEASE.jar
I don't use Spring but in that vast classpath, it looks like you have a mixture of versions

2.0.8
2.1.9
2.5.6
3.2.2

unless various parts can vary in their versions

/apps/com/cust/lib/spring-aop-2.5.6.jar
/apps/com/cust/lib/spring-batch-core-2.1.9.RELEASE.jar
/apps/com/cust/lib/spring-batch-infrastructure-2.1.9.RELEASE.jar
/apps/com/cust/lib/spring-beans-3.2.2.RELEASE.jar
/apps/com/cust/lib/spring-context-3.2.2.RELEASE.jar
/apps/com/cust/lib/spring-core-3.2.2.RELEASE.jar
/apps/com/cust/lib/spring-expression-3.2.2.RELEASE.jar
/apps/com/cust/lib/spring-jdbc-3.2.2.RELEASE.jar
/apps/com/cust/lib/spring-support-2.0.8.jar
/apps/com/cust/lib/spring-tx-3.2.2.RELEASE.jar
Avatar of Jay Roy

ASKER

one quick quiestion

you said
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
doesnt exisit,

but it does point to a xsd file when i click on that link, right
but it does point to a xsd file when i click on that link, right
Yes, sorry. When i first tried it, the link was not found. Is now

Do you still get the same error?

Incidentally THIS suggests you had similar problems to me, since the third possible reason can be eliminated

Another question is this: if you're using 3.2.2, why isn't the schema link more like this?
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
Avatar of Jay Roy

ASKER

i changed 3.1 to 3.2 but still no luck
The same error comes up with 3.2 version aswell.
Yes, i'm not advocating that as a solution. It's more of a why

Can you tell me what this prints on the Unix box please?


wget -q -O /dev/null http://www.springframework.org/schema/beans/spring-beans-3.1.xsd && echo -e '\x64\x6f\x77\x6e\x6c\x6f\x61\x64\x61\x62\x6c\x65'

Open in new window

Avatar of Jay Roy

ASKER

hi,,

$ wget -q -O /dev/null http://www.springframework.org/schema/beans/spring-beans-3.1.xsd && echo -e '\x64\x6f\x77\x6e\x6c\x6f\x61\x64\x61\x62\x6c\x65'

it just hangs

i dont see any output
Sure it hangs and doesn't just return to the prompt?
If you're sure it hangs it looks like

a. you don't have a proper internet connection
or
b. you have not configured your proxy properly

IOW, we're looking at reasons 1) or 2) from the error message given to you
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
In my last post I gave a few things to try, which one fixed your problem? Just out of interest?
Avatar of Jay Roy

ASKER

i was reinventing the wheel by creating a new jar on my own by exporting the project as a jar. What i dint know was maven was also creating a jar.
Once i started using the jar which maven created , i did not find any of the above classpath issues.

thanks.