tags:

views:

48

answers:

2

I am running a web application in tomcat6.0 . My problem is that while starting the Tomcat I need classes from commons-lang.jar. And I need the commons-lang.jar also in my web-app. I placed thic jar in the system classpath of Tomcat. Now I get the SerializationException from SerializationUtils. It tries to find a class which is present in the web-inf/lib directory. I saw the Tomcat documentation for the classloaders. looks like the classes on system classpath cannot see the classes from the application.

What can i do to resolve this problem?

A: 

Put the commons-lang.jar in the Tomcat /lib directory and remove it from your application's WEB-INF/lib.

duffymo
I tried it but it doesnt help. I get Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory on server startup.
tak
Sounds like you're missing the Commons logging JAR now, too. Keep adding JARs until the CNF exceptions go away.
duffymo
It was kind of really a tedious job to put all the jars in the commons classpath and even after copying all the jars the application did not work. so i just created my own class. I had no other alternative.
tak
"Really tedious job" - you don't have a long future as a Java programmer. Programming is full of "tedious" tasks that are necessary to do it correctly. Your self-checked solution might "work", but it's not the right way to go. I'm voting your question and your answer down.
duffymo
well why it was a "really tedious job". It was not a small project but a project for one of the banks. I had almost 15 jars in the systems classpath. As you may know that banks have there own framework. And tomcat was not part of there framework. So what i had to do was to integrate tomcat with this framework. commons-lang was part of there framework and also part of the application. Now if i copied all the jars into the commons lib, i would have to copy them always when there was an update of the framework.
tak
And secondly i tried to copy all the jars to the lib just as a test, but that didnt work, there were other exceptions with the framework. I did this change only after investing three days on this problem. Finally i came to this ugly hack. The only other option that was open to me was to write my own bootstrap which would load the commons-lang from the aplication and not from the systems classpath. Now i leave it upto you to decide, am i still wrong with this decision
tak
Yup, you're still wrong. And it's "their own framework". Check your grammar.
duffymo
can u explain to me why am i still wrong?
tak
Because understanding CLASSPATH and correcting fundamental errors is key to being successful with Java. Your shortcut eliminated the possibility of having to create that SerializationUtils.class to get around it. You still don't understand the problem to its roots, so you won't know the proper thing to do next time.
duffymo
yes... you are right... i think i gave up to time pressure from the management.... will still try to figure out how can i fix it....
tak
A: 

I had to create a class com.SerializationUtils and use this class in the application instead of the SerializationUtils from commons-lang. After this fix, everything works fine.

tak
this is just a workaround...
tak