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

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).

Related

Why jars added to Deployment Assembly do not show up in Project Explorer (Eclipse Photon) under WebContent/WEB-INF/lib folder?

Working on a Dynamic Web Project I added a guava jar file to Deployment Assembly (Eclipse Photon) - thru Add -> Java Path Build Entry (same happens with Add -> Archives From File System)
I see that this jar gets deployed to the server and is actually inside /WEB-INF/lib of the generated and deployed WAR.
But my Project Explorer window looks like this and its WebContent/WEB-INF/lib folder is empty (I did project refresh)!
Is it normal behaviour?
In my opinion it breaks Least Astonishment Principle a lot!
It shouldn't appear there unless you actually copy the jar into the workspace (or link it, possibly).

JBoss 6.1.1.EAP Module Deployment: Class not found

The structure is as follows:
Actually deployed module is EAR.
EAR contains WAR module, and WAR module contains another JAR module.
In this last JAR, there are some generated classes and their parent folder is also used as source folder. Its path is "target/generated-sources/java".
The problem that is killing me, is that the deployed application throws ClassNotFoundException on server start, and the classes in question are the generated ones.
Now the trick:
if I explicitly change the Deployment Assembly in WAR project in Eclipse not to contain JAR project as "project", but as an archive from the JAR's project "target" folder, JBoss sees the generated classes and starts.
This solution however works only until next eclipse maven project update, so manual edit of deployment assembly is not really a solution.
Any ideas how to deploy or reorganise packages correctly?
OK, seems I have found the solution.
I looked through the build-path of the mentioned JAR file and saw that the entry Output folder pointed to target/test-classes.
After changing this entry to target/classes the application deploys and starts without any missing generated classes.
This is what worked for me:
Expand the 'target' folder of your maven project inside Eclipse (Project Explorer View);
Refresh it (F5);
Right click on your project on 'Servers' tab, then select "Full Publish";
Start your JBoss.
I had to enforce the JBoss Tool "Full Publish" to get an updated version of my target folder by Refreshing it manually on eclipse.
I don't know why but sometimes the Publishing from maven projects (even Full Publishes) do not copy classes from the target Project as it is in the file system. Maybe it's using some outdated memory info or some cache...
Anyway, this is what works for me.
After an update to Eclipse 4.15 and JBoss tools I got this problem too.
My solution: project -> properties -> Java Build Path --> Source
There my Output folder from my source was linked to project/target/classes, I changed this to project/target/project-projectversion/WEB-INF/classes
When I looked into the standalone JBoss folder I saw the folder structure of my source, but the classes where missing, when I changed the output folder the classes pop up and everything worked like before.
I am pretty sure the update made the problems.

Deploy a War file with Eclipse and Tomcat 6 without a build file

I know there are a bunch of posts on this topic, but I can't seem to figure it out. Here is my setup:
- Eclipse Indigo
- Tomcat 6
- Struts WAR file that I imported into Eclipse from http://www.manning.com/dbrown/SampleApplication.zip
I added the server to Eclipse, and added the project to the server. It runs fine, but I'd like to make some changes to the XML and java files (not the jsp files). I was under the impression that Eclipse takes care of the deployment after I save and restart the server, but I guess this isn't the case. I looked into creating an ant file to do a custom build, but I'm not really sure how to make it since I don't even know how to do a deployment "manually". How would I go about doing a manual deployment? Thanks.
A war file is usually created by exporting it from an IDE like eclipse, netbeans, etc.
While generating a war file there is 2 options,
You can include your java files with it
You can avoid java files from it.
In both the cases class files will be there which are created from java files. Class files will be able to take care of the actions of java class.
If the war file which you down loaded is not having those java files, you will not be able to use it with eclipse, where as it will work fine if you are putting it into tomcat directory for running.
For running a war file manually just put it into tomcat webapps folder and run tomcat.
Then you can access the pages using the url.
http://localhost:8080/yourprojectname/
If you want to check whether the war file contains any java files, after starting the tomcat server it will extract the war file into the same directry, where you can search for java files.
If you want to run the project from eclipse,
import it into eclipse, open index.jsp page
right click-> run as-> run on server
if you have not yet configured the server yet,select the server in the list, specify its installation path, then add projects into server in next step, finish it. then it will load your project.
Please provide little more details so that we can help you better.
manual: copy the war in the tomcat folder then start tomcat.
if you want to use eclipse you need to click redeploy war first by right clickling the deployed war in the servers tab under tomcat.

java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool

I am tring to configure a dynamic web project using eclipse helos. I use tomcat 6. When I add the libraries to the WebContent/lib it works fine. But I want to a folder called lib in the project's root level(root/lib). When I put my library files to that folder it builds fine. Run fine to the login page. When I try to log in it gives
"java.lang.NoClassDefFoundError: org/apache/commons/pool/impl/GenericObjectPool"
Please help me with this.
You're creating a web app and deploying it as a WAR file in a Java EE container. That means that your deployment must follow the WAR standards. Put your JARs in WEB-INF/lib. The container will find them there.
Tomcat 6 and 7 have changed things up so JDBC driver JARs need to go in the server /lib directory. The app server expects to find them with its class loader. Try putting the MySQL JDBC connector JAR in /lib and see if that helps.

ClassNotFoundException when using User Libraries in Eclipse build path

I'm using Eclipse 3.7 (STS) with Tomcat 7 running inside the IDE. I've created a new Dynamic Web project and added a single JSP file to the web content root folder. I can run Tomcat and access the JSP from within Eclipse with no problems.
I've added a few 3rd party JAR's to the project from User Libraries (I'm not using maven or auto dependecies managment). In the JSP I reference a class from the project's JAR file, I can compile this with no problem, but when I deploy on Tomcat the JSP throws ClassNotFoundException. Clearly, Tomcat can't find the JAR's from my library settings. I tried creating a Run As configuration for Tomcat Server and I set the classpath to match the classpath settings of the project, but I still get the same classnotfound problem.
I could get around the issue by manually copying all project JARs to the WEB-INF/lib directory so the webapp can find all dependencies, but that's absurd and I don't expect that to be the solution since it's a maintenance nightmare.
Am I missing something?
In project's properties, go to Deployment Assembly. Add there the buildpath entries as well which you've manually added as user libraries. It'll end up in /WEB-INF/lib of the deployed WAR.
You'll need to copy the jar files to the WEB-INF/lib folder: that is where they are supposed to be.
Eclipse should offer you the option of generating a WAR file that includes all the dependencies: I haven't used Web Tools for a good while but one way or another all dependencies have to be in WEB-INF/lib or the class loader won't be able to find them.