I'm new to servlets, I got java.lang.ClassNotFoundException whenever I try to include JSON library, I search the web and stackoverflow the only suggestion I found is to install dependencies I've Tried org.json , net.sf.json each with its dependencies nothing works and gives the same exception.
Any idea?
JSONObject is contained in java-json.jar. Make sure that have you have java-json.jar in your classpath. There are multiple places to put jars in tomcat depending which class loader you want the class to load.
If this jar is only required by your application then simply put it under your application directory in
WEB-INF/lib
It is worth reading how classes are loaded in Tomcat to place your jars optimally: http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
Try to put the libs for your web app in the directory
WebContent/WEB-INF/lib
Related
Recently While I was doing a Dynamic web project,I forgot to include OJDBC.jar in the WEB-INF folder.But the code ran file without showing any Class Not Found Exception.But when my friend did the same,Class not found exception was shown.Then when he included the OJDBC.jar in the WEB-INF folder,the code ran fine.I am not able to understand why this is the case.Is it not mandatory to include OJDBC file in WEB-INF folder?And we both used Apache Tomcat Server.
As you can see from the above screenshot,I experimented by not including OJDBC.jar in the WEB-INF folder.The code ran fine.Please tell me why this is the case?
Well, Eclipse builds the context's classpath joining libraries from several locations:
Of corse, the <tomcat_home>\lib\*.jar files.
The <project>\WEB-INF\lib\*.jar files.
... and also the deployment assembly entries (within the project's properties).
Check out every one of these and compare with your partner ones.
I'm coding a little servlet using weblogic.wsee.jaxrpc.ServiceImpl. My IDE(JDeveloper) doesn't say something wrong. But after launching app, I'm catching java.lang.ClassNotFoundException:weblogic.wsee.jaxrpc.ServiceImpl. Should I add new jar files to lib directory? This is what lib contains:
If you use weblogic 12.x then the jar that contains weblogic.wsee.jaxrpc.ServiceImpl is located in
{WL_INSTALL_FOLDER}/wlserver/modules/clients/com.oracle.webservices.wls.jaxws-wlswss-client.jar
or
wls.jaxrpc-client
depending on which one you use.
If you add that to your lib, it should work.
I am working on externalizing Resource adapter rars.
Earlier, the rar were packaged inside the /lib of war and everything worked good. Now to make the war light and also generic, I want to externalize resource adapter.
What I have done yet
Removed rars from war
installed rar externally through WAS7.0 Admin console
configured J2C connection factories for each RAR
I did a clean ,restart and I got some ClassNotFoundErrors.
Why were these errors there :
Basically the rars use some jars that are present inside /lib. so earlier there was no problem but now when I externalized it, I started getting CNFE`s.
How I resolved:
When we install a rar through WAS admin console , there is an option to provide classpath. I provided the jars that were causing issues on classpath there. And I could deploy and start my application
The problem:
When I login to my application. There is a line of code in one of the jars (that was causing issues and was added to classpath of resource adapter , note that currently this is present inside war and also on classpath of resource adapter), that is doing a type cast.
Now on this statement
I get an exception
java.lang.ClassCastException: com.csc.fs.ra.SimpleMappedRecord incompatible with com.csc.fs.ra.SimpleMappedRecord
I dug up and found that a possible cause is multiple version of same jars. which is a case in my case.
i have a version of jar inside war library and also on classpath of resource adapter.
I am kind of out of ideas here. what to do to resolve this kind of situation. please help
Regards
The RAR and the WAR got their own ClassLoader, even if you use the same version of the jar, each one of them loads the class separately and you get ClassCastException.
Before when it was embedded it worked because the RAR was using the same ClassLoader.
If the RAR are now separate I think you will have to put the jars in a shared library so it will be loaded by a single ClassLoader.
You can check the classloaders. It will show you all jars that are loaded.
In my application I am calling a bean from JSP and displaying data.I have kept all required jars in lib folder and that is in build path.When I run this bean it fetches the data successfully. But when I call this bean in JSP it says No Class defination.I found a workaround for this that is putting all the jars also in the lib folder of Tomcat.(apart from keeping in classpath). Means now i have to deploy the war and also put jars in tomcat lib.but why do i have to do this when jars are already in classpath.
thanks.
It sounds like you might be having a conflict with some of the jars. If one of the jars is depending on something provided elsewhere in the tomcat class loader, or if it is providing the same functionality - you could end up with a problem. You used to see this often with a conflicting XML parser implementations.
This has some more information on what is included: http://tomcat.apache.org/tomcat-7.0-doc/class-loader-howto.html
I have added a piece of sharepoint code to the existing java file which was compiling and working fine. The sharepoint code that is written uses some of the external libraries. Now I need to add the external library to the existing project through ANT.
I have done a few modifications in the build.xml file and hence resolved all the compilation errors. However when the code is getting executed, I get an Error message saying "java.lang.NoClassDefFoundError: net/entropysoft/eci/spi/IContentProviderFactory". Please help me resolving this error.
Also please let me know what needs to be added in the build.xml file to resolve the error.
All the jar files is present in the directory "externallibs"
Thanks,
Rajath
You need to have all the jars in the classpath when running the application:
java -cp externallibs/* com.foo.bar.Main
If it's a Java EE web application, the build process should copy all these jars to the WEB-INF/lib folder of the generated web app structure.
java.lang.NoClassDefFoundError: net/entropysoft/eci/spi/IContentProviderFactory does not mean the class net.entropysoft.eci.spi.IContentProviderFactory is not found. It means the class that is used within this class are not found anywhere in the classpath. This error is thrown when the class loader is trying to load the class but it cannot properly initialize the class definition.
To solve this problem, you will need to look at the source code of the class net.entropysoft.eci.spi.IContentProviderFactory, usually at the import section, and determine what is the missing Java class and which library the missing class is in. Once you know you can add that library to your classpath using the answer by JB Nizet. If you run it from IDE, then you will need to add that library to you build.xml.