Getting error while running the Web Application? - eclipse

I am creating a Dynamic web project. I have made a home JSP file and kept a button on this JSP page. When I click on this page then it calls the HelloServlet where I am accessing the Cassandra DataBase. I have added all the required Jars file to the project . But when I click on the button on the JSP page some exception is coming which is given here
HTTP Status 500 - Error instantiating servlet class cassandra.HelloServlet
type:- Exception report
message:- Error instantiating servlet class cassandra.HelloServlet
description:- The server encountered an internal error that prevented it from fulfilling this request.
exception:-javax.servlet.ServletException: Error instantiating servlet class cassandra.HelloServlet
............
root cause:- java.lang.NoClassDefFoundError: org/apache/thrift/transport/TTransport
........................
root cause:- java.lang.ClassNotFoundException: org.apache.thrift.transport.TTransport
......... ............
Also , I am able to perform my job when I am creating a simple Java project using the same code and same Jars.
Looking for Help!

You have added the jar files in the project build path. This path is used to compile your application, but it's different from the runtime classpath. At runtime, the container looks for libraries in the WEB-INF/lib directory of the deployed webapp.
Under Eclipse, the libraries that must be present at runtime under WEB-INF/lib must simply be dropped in the folder WebContent/WEB-INF/lib of your web project. Eclipse automatically adds these to the build path and adds them to the WEB-INF/lib directory if the deployed app, so that they're available also at runtime.
So, remove all the cassandra jars from your build path, and drop them in WebContent/WEB-INF/lib. Once done, they will appear under the Web App Libraries node of your project.

Related

Hibernate configuration with tomcat and eclipse

I'm creating a webApp in eclipse using tomcat & hibernate (for mysql). Ive unit tested by code and I am able to connect to the db and pull data, but I'm running into issues when trying it from the web app.
From the exception it looks like it isnt able to get to the hibernate.cfg.xml, but I've tried placing the file in the src folder, WEB-INF/lib & WEB-INF/classes but I still get the same error.
The line of code that it's failing on is:
Configuration configuration = new Configuration();
I would really really appreciate any help!
ClassPath References:
Project References:
Stacktrace:
java.lang.ExceptionInInitializerError
org.hibernate.cfg.Configuration.reset(Configuration.java:324)
org.hibernate.cfg.Configuration.<init>(Configuration.java:289)
org.hibernate.cfg.Configuration.<init>(Configuration.java:293)
root cause
java.lang.NullPointerException
org.hibernate.internal.util.ConfigHelper.getResourceAsStream(ConfigHelper.java:170)
org.hibernate.cfg.Environment.<clinit>(Environment.java:221)
org.hibernate.cfg.Configuration.reset(Configuration.java:324)
org.hibernate.cfg.Configuration.<init>(Configuration.java:289)
org.hibernate.cfg.Configuration.<init>(Configuration.java:293)
SOLUTION
Thanks to #Engineer, I was able to solve this by removing the jars from WEF-INF/lib & from the class path of the run configuration. Then I added them back using the "Deployment Assembly" menu in eclipse. I also have my project references here.
From Ranga Reddy:
Problem: Because of adding the jars in user library class path.
Solution: Instead of adding the jar files using User Library add the jars using classpath.

jars getting loaded twice in eclipse

Problem: jar getting loaded twice in eclipse
Description:
I copied and pasted struts jar into lib folder of WEB-INF.
The jars icon get changed .
If I remove the jars in build path they get back to normal state but program says package not found.
My program is correct but i am getting
Resource not found ie HTTP-404
error due to this.
So please tell me how to load jars?
You can do two things
go to the build path and create user define library for you jar file and
when you deleting it from build path that mean it is not configured for you application but some times it shows like it is configured. For that you again go to lib and add the jar to build path

Java EE, GWT, NoClassDefException

I have an app, built on GWT (google web toolkit) and JPA (eclipselink 2.3). it's not using GAE (app engine).
when I finished application, I ran 'google->gwt compile' menu in eclipse and then uploaded /war content to the tomcat directory...
application is running, but when I try to do one specific action in gui, I get an error message and Tomcat log contains this exception: http://paste2.org/p/1879857 (java.lang.NoClassDefFoundError)
during development of the application, I encountered this kind of exception several times, it was always caused by absence of library .jar file in the war/WEB-INF/lib/... anytime it has occurred, I stored .jar to the folder and it worked... but not this time...
this class is located in gwt-dev.jar (yes, it is there - have searched the archive) and it didn't help me to store archive to the lib/ folder...
it is also included in classpath, and compiler had no problem... compilation finished without errors (so compiler can see the class).
do you have any idea, how to make tomcat to see the class?
thanks
gwt-dev.jar shouldn't be in WEB-INF/lib/, it is the GWT compiler, and shouldn't be needed or used at runtime. At the same time, that HashSet (com.google.gwt.dev.util.collect.HashSet, part of dev mode) shouldn't be used outside the compiler - use java.util.HashSet instead.
Change the HashSet import in GroupImpl.java from com.google.gwt.dev.util.collect.HashSet to java.util.HashSet. You shouldn't need gwt-dev.jar to run your application.

Eclipse and Tomcat: Unable to start a War project

My eclipse setup for web project worked before. But all of the sudden it stops working.
Eclipse version Build id: 20100218-1602
It is a very standard setup. I have a servers project setup in eclipse. I have defined an tomcat server in it. I was able to run my web project this way.
Suddenly for some reason today I saw this exception:
org.springframework.beans.factory.CannotLoadBeanClassException:
Error loading class [some.company.persistence.dao.hbm.ProductDaoImpl]
for bean with name 'productDao' defined in class path resource [SomeDB.xml]:
problem with class file or dependent class; nested exception is
java.lang.NoClassDefFoundError: org/springframework/orm/hibernate3/support
/HibernateDaoSupport
Based on the message above, can anyone suggest what may be broken?
Looks like the hibernate library is missing from the project's classpath. Figure out which one of the spring jars contains HibernateDaoSupport and add it to your project's classpath.

Spring can't find a lib and webapp doesn't start up in tomcat 6

I've this problem using STS: I'm building a simple Spring app, just to try out features like MVC and persistence. Now I've created something very simple, out of a bunch of tutorials for Spring 3, that I'm using. The application fails with this, during server startup:
Code:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0': Initialization of bean failed; nested exception is org.springframework.beans.factory.CannotLoadBeanClassException: Cannot find class [org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean] for bean with name 'mySessionFactory' defined in ServletContext resource [/WEB-INF/spring/appServlet/servlet-context.xml]; nested exception is java.lang.ClassNotFoundException: org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean
but I've org.springframework.orm in web-inf/classes folder (I even tried putting it in web-inf/lib). As I copied these libs there, the came out in Web App Libraries folder. Building this project in STS works fine as this dependency is set up in build path throught project properties, but how do I transfer the libs to the web app? (I'm using Tomcat 6 as it is the server I'm going to use sometime in the future for production). Is this a config problem of my XML? Or am I just missing the right way to put this lib? (I encountered the same problem before, but adding the needed lib in classes worked it out). More than this I that if I browse inside my workspace to the folder where the working folder of tomcat should be, I can't find any work directory and any commo
Go to the Servers view and double click on Tomcat Server which will open up a Tomcat Overview page. This will show you the server path and deploy path which Eclipse is using to publish your webapps to.
For example, mine are:
Server path: .metadata\.plugins\org.eclipse.wst.server.core\tmp0
Deploy path: wtpwebapps
Now in a Command Prompt (or Explorer) browse to %ECLIPSE_HOME%\workspaces\default\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps and you should see your webapp. Go into the WEB-INF\lib directory and check if your jar is there.
A few things to try:
If the jar is not in WEB-INF\lib, you might need to republish it. Right-click on the Tomcat in the Servers view and click Publish. Does it appear? If not, Right-click on the Tomcat again and this time select Clean... which will clean out everything and republish. If this doesn't work, the brute force approach would be to delete the files manually and then tell Eclipse to republish them.
Clean your work directory, by right-clicking the webapp under Tomcat in the Servers view and selecting Clean module work directory. Or do it manually by deleting from %ECLIPSE_HOME%\workspaces\default\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost
You should also try closing-reopening/cleaning/rebuilding/refreshing your webapp project just in case Eclipse hasn't picked up the changes.
You need to put the various Spring JARs into your WEB-INF/lib directory (WEB-INF/classes is no use for JAR files).
You don't just need org.springframework.orm, you need most of them (see here for dependency diagram).
At least the libary jar files must be located at WEB-INF/lib within your war file. And you only need to deploy the war file to your productiv web server.
If you use STS but your Project is not a Maven project: then you need to put the files in <projectRoot>/WebContent/WEB-INF/libs .(to build the war with Eclipse/STS you need to execute Export/Web/WAR file.)
If you use Maven, then you need the specify your dependencies in the pom.xml, and use maven to package the war (run as/Maven package).