Tomcat reporting IncompatibleClassChangeError - classpath problem? - eclipse

I'm trying to deploy an application to Tomcat 7 on a Windows server. I have a local copy set up and have tested with Eclipse without any trouble, but on the production server I get IncompatibleClassChangeError messages.
This had been a problem on the local server when there were problems with the classpath, but I configured the correct classpath in the server properties inside Eclipse and everything ran fine.
I'm new to Tomcat and from what I understand it should be reading jar files from my my WEB_INFO/classes directory, but when my jars are there the app doesn't want to load at all. When I move them to the $CATALINA_HOME/lib (I realize that's not where they should go) the app loads fine but reports the IncompatibleClassChangeError.
Why aren't my jars being read from WEB-INF/classes? Is there some configuration I should look at to fix this?

Webapp-specific JAR files should go in Webapp/WEB-INF/lib, not in Webapp/WEB-INF/classes. The Tomcat/lib should only be used for appserver specific libraries and optionally also JAR files which should be shared among the deployed webapplications.
There might be more into the IncompatibleClassChangeError, this can have an entirely different cause. But first try getting the JAR's in the right place. If in vain, then please update your question to include the detail message. This at least smells that you're putting JAR files of a different appserver make/version in the classpath.

Related

Tomcat and Eclipse vs Intellij

I am working with Intellij but some of my co-workers don't. When I was writing install doc, I realized that Tomcat is not managed the same way on the two IDEs.
Which is a problem considering what happened next when I tried to set up our project on Eclipse.
Basically, on Intellij, you select a Tomcat on your computer and it will literally copy the war into the webapps folder and run the server with everything working fine.
I am not a user of Eclipse so I might have misunderstood something, but I found that when you create a Tomcat server, it will embed the one you gave it to it. Doing that is a bit of an issue when you are working with logback, because usually you set your logs location directly into the Tomcat folder. And in Eclipse you are working out of this folder.
So, I can't run my application because it can't find the location of the logs folder at the fine place.
Is there a way to use Tomcat in Eclipse like Intellij? Or did I just miss something because I am kind of new with Eclipse?
See the FAQ: (1) (2)
I found that when you create a Tomcat server, it will embed the one you gave it to it.
You have to be more specific with your description. How you do things and what do you see. What do you mean by "embed"? What is the actual failure that you are observing with your logging?
There are different ways to do things.
For me by default Eclipse does not embed Tomcat, but runs it as a proper java process. (org.apache.catalina.startup.Bootstrap) You should be able to see it with jconsole and similar tools.
It runs your web application expanded, i.e. without zipping it into a war file. It creates a separate configuration of Tomcat, i.e. runs it with separate CATALINA_HOME and CATALINA_BASE directories (as documented in RUNNING.txt file of Apache Tomcat). The CATALINA_HOME directory stays untouched and CATALINA_BASE directory is ${workspace}/.metadata/.plugins/org.eclipse.wst.server.core/tmp0 etc. A logs directory can be found there.
One known caveat is that java.util.logging is not configured by default (the system properties java.util.logging.manager and others are not set). See "How do I enable the JULI logging" item in the FAQ. -- In the same way you will set any other system properties that you may need.
The default configuration of java.util.logging (as provided by JRE) is to log everything to the console, without creating any files.

JBoss Client directory

I recently started learning more about JBoss Application sever. After installation I was looking inside all directories created by JBoss installation. (I'm using JBoss AS version - jboss-5.0.1.GA)
I referred documentation available at this link
It says 'client' directory contains Jar files needed by remote clients.
client: The JARs that are required for clients that run outside of JBoss are located in the client directory.
When I looked inside 'client' directory after installation, it contains 90 jar files overall. Does that mean If I create a remote ejb client I would need to include all the 90 jars in my remote application classpath?
With JBoss AS 5.x things got complicated.
Placing all of the client jar files on classpath will certainly work.
In JBoss 4.x there was an option to use jbossall-client.jar which integrated other numerous client libs into single file. If you'll look into same named jar in JBoss 5.x you'll find out that it's reduced to manifest referencing other jars. Placing this single jar in your classpath will work as long as all of the jars referenced by manifest are present in the same directory.
If accessing remote EJB is all you need then only a subset of jars is required, unfortunatelly it's hard to tell which ones is it.
Following this coderanch link (I've found it here on SO) you'll find such subset prepared for JBoss 5.1.0.GA.
Be warned though, list of jars published on coderanch has abbreviated names, some misquotations and at least two jars are not present in server version 5.0.1. If reducing number of dependencies is your priority, use this list wisely and enhance/extend it by trials and errors.

Running servlet within Eclipse requires libs to be defined 3 times - am I doing something wrong?

Hullo - issue is this:
I wrote a servlet in Eclipse which requires mysql-connector-java-5.1.22-bin.jar
To compile I need to add the jar via the project's "Java Build Path"
To deploy I need to add the jar to the project's "Deployment Assembly"
To run the servlet within eclipse I need to add the jar to the servlet's Run Configuration -> Classpath
It's not the end of the world re-re-repeating myself like this, but it does seem odd.
Given that Eclipse gets a lot of other stuff correct I'm guessing / hoping that maybe I'm overlooking some feature to avoid this silliness (I cannot imagine a scenario where you'd benefit from entering this in 3 different spots ... but maybe I'm being uncreative here ...).
Insights appreciated :-)
The only thing you need to do is to drop the jar in WebContent/WEB-INF/lib.
You are developing a Java Web project, so the traditional place to put the required libs (JAR files etc) is under /WEB-INF/lib. And you do it only once.
In Eclipse, when you create Dynamic Web Project the appropriate project structure is generated for you (this is a development structure). In this case you place your JAR files in ProjectName/WebContent/WEB-INF/lib folder. And this folder is *automatically included in the project's build path.
Considering the fact that it is a Java Web project (you said you use servlets) you have to deploy your web app to some Application Server, like GlassFish, JBoss, WebLogic, WebSphere etc, or more simple Web Container like Apache Tomcat. If you do this thru Eclipse, then again your web project is automatically deployed.
NB!
There may be some additional details related to using libraries.
For instance, when it comes to using database drivers (MySql, PostgreSQL, Oracle etc) Tomcat advises the following while configuring JNDI Datasource (quote):
Before you proceed, don't forget to copy the JDBC Driver's jar into
$CATALINA_HOME/lib
In your case (MySQL) see the example here: MySQL DBCP Example
Also see my answer related to Webapp configuration file organization convention.
Hope this will help you.
P.S. Here is a step-by-step example: How do I access MySQL from a web application?

Getting Error when deploying on Tomcat

I have already compiled my application, when I am running it in web
mode from Eclipse everything is working perfectly fine, no error at
all. In my project, i'm using several libraries such as hibernate. All
libraries have been correctly been placed on the classpath as well as
in the lib folder in web-inf.
however when i'm deploying it on tomcat, i'm getting several problem,
first no data is being loaded from database. I was using a lib for
capcha at http://www.javacodegeeks.com/2010/06/add-captcha-gwt-application.html. That also is not working well
I am also trying it on Jetty with the same problem
Can someone please help, i've got to deploy this system??
Be sure to include all required libraries in your /war/WEB-INF/lib folder
Yes, it was a problem of lib, whenever deploying your app on the server, make sure that u have the required libs that r on your classpath in the folder webinf/lib.

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