Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

missing classes after publish web project into tomcat using eclipse wtp

I have several dynamic web projects in my workspace, each contains classes and refers to other utility projects (simple Java Projects), and to 3rd party jars.

These apps (dynamic web projects) are deployed on tomcat v6.0.6 using eclipse WTP (Helios 3.6)

When I update my workspace and new classes/resources/jars are extracted from the SVN repository, I re-publish my apps in tomcat apps, and restart it.

Occasionally, when tomcat starts one of my apps, it throws ClassNotFoundException, or complains about other missing resource. Sometimes I see that the a deployed resource (spring beans xml for example) is not up to date, and has 'old' content in it.

The common anti-voodoo-black-magic treatment I use: * stop / start tomcat * clean (when right click on the server configuration) * clean tomcat work directory * remove all apps from tomcat, clean, restart tomcat, add all apps

I need to run this 'procedure' several time until problem is solved.

Do you guys suffer from it as well ? Is this a known bug ? Any suggestions how to tackle it ? is using jars instead of utility projects will solve/reduce this problems?

I would consider using Embedded Jetty instead, I just want to avoid from proprietary scripts for running Jetty on a 'production' environment.

-- Yonatan

like image 531
Yonatan Maman Avatar asked Dec 02 '10 14:12

Yonatan Maman


2 Answers

It happened to me a lot. I wouldn't call that Voodoo. I think that Eclipse WTP doesn't work well when you change stuff in the background (e.g. a maven build).

What I do to solve this is to avoid using it altogether. Instead I use Maven WAR plugin to deploy the application:

mvn war:inplace tomcat:inplace -DskipTests=true

This works very fast, as it doesn't need to assemble, and package the war.

Then to undeploy the application:

mvn tomcat:undeploy

I have scripts that

  • deploy and start tomact
  • undeploy and stop tomcat

It looks something like this:

Start tomcat and deploy app:

#!/bin/sh

if [ -f $CATALINA_PID ]; then
  echo "tomcat already running with pid " `cat $CATALINA_PID`
  exit 1
fi

java -Dmy.arg=val -Dcatalina.home=<catalina-home> -Dlog4j.configuration=file:///log4j.xml -classpath <path-to-tomcat-lib>/bootstrap.jar:/usr/lib/jvm/java-6-sun-1.6.0.20/lib/tools.jar org.apache.catalina.startup.Bootstrap start &

echo $! > $CATALINA_PID

mvn war:inplace tomcat:inplace -DskipTests=true

Undeploy and Stop tomcat:

#!/bin/sh

mvn tomcat:undeploy

<path-to-tomcat>/shutdown.sh -force

rm $CATALINA_PID

The same with probably any other build script - its just a matter of how much code you will have to write.

I chose Maven's war:inplace goal is since it does very little, and thus runs very quickly. See here: maven.apache.org/plugins/maven-war-plugin/usage.html.

BTW, ANT and Gradle have a war task/plugin which can probably be configured to do something similar (I don't really remember...)

Hope this helps.

like image 128
Eran Harel Avatar answered Oct 18 '22 19:10

Eran Harel


Another thing to look out for is that Project -> Build Automatically should be enabled and the project should not have any build path problems.

Open the navigator view and confirm that the build folder is having generated class files.

If the files are not being built they won't be published. Though this seems obvious it is easy to over look and wasted a lot of my time.

like image 38
Kshitiz Sharma Avatar answered Oct 18 '22 18:10

Kshitiz Sharma