This week's book giveaway is in the OCMJEA forum. We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line! See this thread for details.
Hi, Sorry for being little over descriptive here. I have an issue deserializing a file that contains a Map<String, List<POJOs>>. These POJO bean classes are stored in a jar file uder web-app/lib. I can deserialize the file from a standalone java program, from tomcat web app when tomcat is started from within Eclipse IDE; but I can not get it to work from the same webapp when tomcat is started in standalone mode (not from within IDE). I have some javabeans added into a List object, which is added to a LinkedHashMap object in the serialized file.
This is the partial stack trace -
This is the code -
I even tried to override the default class loader as -
It still doesn't work. I also tried printing the default class loader and the loader after overriding it. This is what I see - >When run from a standalone java class- Default Class Loader -> <b>sun.misc.Launcher$AppClassLoader@a39137</b> URLClassLoader Class Loader -> <b>java.net.URLClassLoader@127f79d</b>
>When run from tomcat started directly (not from IDE)- Default Class Loader -> WebappClassLoader delegate: false repositories: /WEB-INF/classes/ ----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader@25c828 (<i>these last 3 lines are automatically printed</i>
>When run from tomcat started within Eclipse- Default Class Loader -> WebappClassLoader delegate: false repositories: /WEB-INF/classes/ ----------> Parent Classloader: org.apache.catalina.loader.StandardClassLoader@10d4f27
So, the class loaders are same whether or not the tomcat is started from within IDE. The class which is not found by the class loader, is actually there in a jar file in WEB-IN\lib. I tried everything I found on google but I can't get it to work. As I said, it works when I start tomcat from eclipse. Am I missing anything? If this is a classpath issue, I am not sure how should I resolve it as everything is already there in the web application. Appreciate your help.
Replacing the Classloader in your web app is neither necessary nor well-advised. Instead, it's just important to make sure everything's in the right place and configured properly. When starting Tomcat from Eclipse, the web app is being deployed by the IDE, and maybe things are being set up properly; as opposed to when you do it outside, something might be in the wrong place.
Do you really mean web-app/lib? Do you mean <your-web-app>/WEB-INF/lib ? That's where the jar would belong.
Thanks for the reply and thanks a lot for the warm welcome !!
I apologize to have incorrectly mentioned the lib path as of the web-app/lib. I actually meant it to be <my-web-app-in-tomcat>\WEB-INF\lib where the jar
I am able to use all the classes from this jar in other pieces of the application, but it's just that somehow it is not found when I try to de-serialize a file which uses a few classes from this jar. In fact, the piece of code where I try to de-serialize, I query my database before it and populate results of that in one of such beans. In other words, I am confident that those bean classes from the jar file are available at runtime in my application code and UI pages. I also made sure that the package/classnames are accurate. I am sure that there is no problem with the deployment as I have been building this application over a year now and I use those beans to contain my database data.
Do I have to add any classpath in the tomcat startup scripts?
subject: ClassNotFoundException when deserialized from tomcat web app