Solved

spring on unix box

Posted on 2013-05-09
27
791 Views
Last Modified: 2013-05-17
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
0
Comment
Question by:royjayd
  • 13
  • 9
  • 5
27 Comments
 
LVL 35

Expert Comment

by:mccarl
ID: 39154255
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.
0
 

Author Comment

by:royjayd
ID: 39154271
>>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.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39154284
Can you post your CLASSPATH here then? I still think it is a case where not ALL the dependencies are satisfied.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39155093
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
0
 

Author Comment

by:royjayd
ID: 39155276
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.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39155466
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.
0
 

Author Comment

by:royjayd
ID: 39155532
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
....
0
 

Author Comment

by:royjayd
ID: 39155591
and this is my command
java -cp $CLASSPATH;$HOME/Customer.jar -Denv=dev com.test.CustomerMain param1
0
 
LVL 86

Assisted Solution

by:CEHJ
CEHJ earned 250 total points
ID: 39155629
java -cp $CLASSPATH;$HOME/Customer.jar -Denv=dev com.test.CustomerMain param1 

Open in new window

is wrong. That's two separate commands in most Unix shells. You're using the wrong path separator. It's a colon in Unix, not a semicolon
0
 

Author Comment

by:royjayd
ID: 39155703
changed to
>>java -cp $CLASSPATH:$HOME/Customer.jar -Denv=dev com.test.CustomerMain param1  
now it doesnt look like the main method is invoked.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39155727
What output did you get?

Please post output of

echo $CLASSPATH

Open in new window

0
 

Author Comment

by:royjayd
ID: 39155824
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
0
 

Author Comment

by:royjayd
ID: 39155888
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)
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 86

Expert Comment

by:CEHJ
ID: 39156003
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
0
 

Author Comment

by:royjayd
ID: 39156005
hmmmm strange, i see that too, but it works from windows so i am confused
0
 

Author Comment

by:royjayd
ID: 39156011
i am using spring-beans-3.2.2.RELEASE.jar
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39156038
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
0
 

Author Comment

by:royjayd
ID: 39156075
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39156402
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
0
 

Author Comment

by:royjayd
ID: 39156520
i changed 3.1 to 3.2 but still no luck
The same error comes up with 3.2 version aswell.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39156693
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

0
 

Author Comment

by:royjayd
ID: 39156723
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
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39157113
Sure it hangs and doesn't just return to the prompt?
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39157242
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
0
 
LVL 35

Accepted Solution

by:
mccarl earned 250 total points
ID: 39158147
First thing to try.. you have in your "schemaLocation" two different mappings for the spring batch namespace. Get rid of one of them. May not be the cause of your issue, but good to eliminate the possibility.

The version number of the various "spring" jar's don't ALL need to be the same. The "spring-batch" one's will run a different release/version schedule and so that is alright. I don't know what "spring-support" is, never seen it before. But the other "spring-*" should all be the same, so in this case "spring-aop" should be version 3.2.2 (not 100% sure that that will be your issue, but best to sort that out). Although, just noticed now that your schemaLocation refers to a "spring-aop-3.0.xsd" and that definitely won't be available and that is more likely to be your issue. Get all the spring jar versions correct, and get all the xsd versions correct in your schemaLocation!

As for being able to access those "links", that shouldn't be necessary. But this possibly is a reason why it is working on your Windows machine but not your Unix box. The .xsd's are actually included in the .jar files along with a "spring.schemas" file that maps the "http://....." schemaLocations into the location of the .xsd's on the classpath. However, if that fails to locate the .xsd for whatever reason, a web lookup will be attempted. So, this web lookup is probably successful on your Windows box but failing on Unix. The point is though to fix it so that it doesn't need to even try retrieving the xsd from the web.

Now for the reason of the above, I still think it is classpath issues. Your classpath as you posted above, has a lot of items, a lot are duplicates, and there are some wildcard entries in there. My recommendation would be to a) download again the spring framework download and make sure you get all the same version jars in one location, b) also gather JUST the other dependencies that you need and nothing extra and put those with the spring jars, and c) set your classpath with JUST those jars that truly are dependencies of your app.

Also, to help narrow done exactly what the issue is, try specifying the schemaLocation for the beans namespace without the version at all, ie. http://www.springframework.org/schema/beans/spring-beans.xsd   This will allow Spring to select the highest version that it thinks is available. If it works, then somehow you are including a spring version that is less than 3.1, hence why it is saying that it failed to load the 3.1.xsd. If it still doesn't work, that your issue is probably that the right jars are just not be included.
0
 
LVL 35

Expert Comment

by:mccarl
ID: 39176247
In my last post I gave a few things to try, which one fixed your problem? Just out of interest?
0
 

Author Comment

by:royjayd
ID: 39176290
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.
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Java 1603 Error 3 45
sumHeights2  challenge 7 78
network + 7 73
Requested array size exceeds VM limit 3 51
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now