missing classes after publish web project into tomcat using eclipse wtp

10,558

Solution 1

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.

Solution 2

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.

Solution 3

Interesting behaviour.... Something similar was happening on my Linux machine due to permission issues.

Anyway, i suggest not to use WTP. Try ant build script instead. Its simple and for me it works brilliant.

Solution 4

Been working with Eclipse since it came out, these problems have always existed. Arrived here because atm my web.xml doesn't get deployed anymore. Especially in combination with m2eclipse you'll never know what happens when you try to start your Tomcat. Everybody I know how has worked with Eclipse has these problems, I don't understand why they don't get fixed...and unfortunately working as a contractor means I can't choose my IDE or the container or the way publishing is done, so most of the time I'm stuck with WTP.

Solution 5

I had a similar problem. When I published a web application, Eclipse was not including one of the jar and hence publish to sever through Eclipse fails. I corrected this by modifying the .classpath file of the project to correct dependency as below. To makes sure that its in sync with other jars configuration.

<classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.17/log4j-1.2.17.jar" sourcepath="M2_REPO/log4j/log4j/1.2.17/log4j-1.2.17-sources.jar">
            <attributes>
            <attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
        </attributes>
        </classpathentry>
Share:
10,558
Yonatan Maman
Author by

Yonatan Maman

Updated on July 20, 2022

Comments

  • Yonatan Maman
    Yonatan Maman almost 2 years

    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

  • Yonatan Maman
    Yonatan Maman over 13 years
    eran- does it mean that I need to use maven to manage all my dependencies? or I can I use it for war deployment only?
  • Eran Harel
    Eran Harel over 13 years
    Yonatan, maven is not a must here. Since I use maven anyway, it was the simplest solution for me. You can do the same with 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...).
  • Eran Harel
    Eran Harel over 13 years
    Yonatan, is there anything missing in my reply?
  • mjaggard
    mjaggard almost 11 years
    I'm not using maven at all and I have the same problem. Even when the resources have changed IN eclipse.
  • mjaggard
    mjaggard almost 11 years
    That bug says fixed in 3.4.2 but I'm still seeing the problem in 4.2
  • Jules
    Jules almost 11 years
    Thats WTP 3.4.2, not Eclipse 3.4.2. WTP 3.4.2 has not yet been included in any standard distribution of Eclipse AFAIK; it is apparently slated to be included in Kepler (4.3), which is due to be released next month.
  • mjaggard
    mjaggard almost 11 years
    Thanks, unfortunately I'm unable to remove my down vote on your answer.
  • David Balažic
    David Balažic over 8 years
    I have the same problem with Kepler SR2.
  • Kevin Deenanauth
    Kevin Deenanauth over 7 years
    Thanks so much - this is the answer!