简体   繁体   中英

How to debug issues with deploying to tomcat from eclipse?

I've inherited a Spring web app. It's a gradle web app project that I've imported into Eclipse. We're using Eclipse 4.7.3, Tomcat 7.0.47 and JDK 1.8.0.151.

The problem is that when I deploy the project to Tomcat from Eclipse, some of the dependency jars are not copied to the project lib directory. When TC tries to start the web app, there are ClassNotFoundException errors.

I'm new to Java web apps, so what I need is some tips for verifying my project import/build/deploy.

Here's what I've done so far:

  • Install Tomcat 7.0.47 (don't start it after install) Install Eclipse 4.7.3 JavaEE flavor (which comes with Buildship Gradle integration 2.0 installed)
  • Import my project as a Gradle project (File -> Import -> Gradle -> Existing Gradle Project). I point at the project root, choose the web project for deployment, and use the default settings.
  • Add a server to the project (from Server view click Add -> choose
    Tomcat 7.0 -> point to TC root)
  • Right click the web target and select Run As -> Run As Server and choose the TC 7 server I added.

At this point the project builds and deploys. The console shows the TC log. TC starts but the shows an error when it attempts to start the web app (for example):

Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level

I could copy jars but it's my impression Gradle should be grabbing the dependency jars during deployment. I can verify that some are copied, but others are missing. How can I debug this issue?

Here's part of my build.gradle file

buildscript {
  repositories {
    maven {
      url projectDownloadUrl 
    }
  }
  dependencies {
    classpath lib_license_gradle_plugin
  }
}

The web app is deployed to ...eclipse-workspace.metadata.plugins\\org.eclipse.wst.server.core\\tmp0. The lib directory here contains some of the deployed dependency jars. The gradle.properties file contains a list of dependencies, for example

lib_apache_tomee=org.apache.openejb:apache-tomee:1.7.1

This is apparently not the place to ask and answer Gradle/Tomcat questions. I figured out the issue shortly after posting, and not wanting to disappoint the 40 people who've come here for help since then, thought I should finally answer my own question.

First, I was on the right track on how to debug deployment of a gradle/maven app in Eclipse. After it deploys you can check which jars are in the deployment directory. Eclipse deploys locally to a place similar to c:\\users\\\\eclipse-workspace.metadata.plugins\\org.eclipse.wst.server.core.

Second, the immediate problem I was having was due to using Tomcat instead of Tomcat EE. The answer to this was right in the question:

lib_apache_tomee=org.apache.openejb:apache-tomee:1.7.1

Tomee is Tomcat + Java Enterprise Edition, which includes some extra logging and other jars, the ones I was missing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM