Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug Google App Engine servlets?

I'm new to App Engine, and I'm trying out some sample web applications in Java. I haven't been able to figure out how to debug the java web application project in eclipse.

When I start the debug configuration, jetty server thats part of the SDK starts up and I'm able to access my page from the browser. But none of my breakpoints in the servlets get hit. Am I missing some configuration for debugging?

like image 883
Anand Avatar asked Feb 29 '12 17:02

Anand


2 Answers

Assuming you've installed the Google Plugin for Eclipse, it should be a simple matter of:

Run menu -> Debug As -> Web Application

This of course runs your application in the web server inside the Eclipse debugger. See Running the Project for details.

like image 50
Marvin Pinto Avatar answered Oct 04 '22 13:10

Marvin Pinto


For anyone trying to debug Google App Engine using Eclipse but without using GAE Eclipse Plugin, I have written a detailed answer here: Dev workflow for app engine + modules + maven

As asked, here is a copy of the answer:


I am using a similar structure with a small difference. The top level directory has war and ear and then they contain their specific pom.xml. I use Eclipse for debugging, and I am able to hot deploy "most of the time" and I am not using Eclipse plugin, which (I

understand) is what you want. Directory Structure

.
|-- pom.xml
|-- README.md
|-- my-ear
|   |-- devpid
|   |-- pom.xml
|   `-- src
|       `-- main
|           `-- application
|               `-- META-INF
`-- my-war
    |-- build
    |   `-- classes
    |       |-- main
    |       |   |-- java
    |       |   `-- webapp
    |       `-- test
    |           `-- java
    |-- pom.xml
    `-- src
        |-- main
        |   |-- java
        |   |   `-- com
        |   `-- webapp
        |       |-- css
        |       |-- favicon.ico
        |       |-- index.html
        |       |-- js
        |       |-- test.html
        |       `-- WEB-INF
        `-- test
            `-- java

Tools

  • Eclipse Luna without Google App Engine Plugin (or SDK)
  • Maven 3.2.1
  • Google App Engine SDK 1.9.6

Dev Workflow

  1. If you already have source code, keep it somewhere else and generate a skeleton using mvn appengine command.
  2. Run the first cut with a simple Hello World using only maven and terminal and mvn appengine:devserver command.
  3. Once done, generate the eclipse project.
  4. Import the eclipse project as a Maven project. It will see the jars via Maven. I won't have written this answer before Luna as it required too many tweaks. In Luna, this works automatically.
  5. The step above will create three projects, top level, ear and war each with pom.xml - It's OK.
  6. In eclipse, provide the output directory as war/target directory. This is the step which makes it possible to hot deploy.
  7. In maven ear/pom.xml, add xArgs to appengine plugin for running in debug mode.

    <plugin>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
        <version>${appengine.target.version}</version>
        <configuration>
            <jvmFlags>
            <jvmFlag>-Xdebug</jvmFlag>
                <jvmFlag>-Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n</jvmFlag>
            </jvmFlags>
            <disableUpdateCheck>true</disableUpdateCheck>
        </configuration>
    </plugin>
    
  8. Notice the suspend=n.

  9. Run the app engine from outside eclipse using mvn appengine:devserver from the ear directory. I use this command: `mvn appengine:devserver > ~/.logs/.appengine.devserver.logs & echo $!

    devpid` Let's call this Terminal 1.

  10. An advantage of this method is that your console is not captured by Eclipse, so you are free to use a tool of your choice to view it, like multitail etc. I use this simple tail command: tail -f ~/.logs/.appengine.devserver.logs | sed 's/INFO/^[[0;34m&^[[0m/g;s/ERROR/^[[0;31m&^[[0m/g;s/WARN\|WARNING/^[[0;35m&^[[0m/g;s/SEVERE\|FATAL/^[[0;31;47m&^[[0m/g' The above is a difficult to type command. Every instance of ^[ is actually Ctrl+V Esc - it is worth the effort of typing it once. But this is of course subjective and up to you.
  11. In Eclipse, create a Debug Profile for your project under Remote Java Application - select the war project and socket attach options.

This step is available on the internet at many places, here is an image nevertheless Debug Config, Remote Application, War Socket Attach

  1. Open another terminal, Terminal 2 in the war directory and keep it open in order to run mvn compile install when you need to.
  2. You are good to go. You should be able to integrate your source code by just pasting it at the right place. You should also be able to use standard debugging techniques. Eclipse will compile at the right location and devserver will detect it all right. If Eclipse throws a warning, ignore it.
  3. This works most of the time. Sometimes, you save something that breaks compilation of the whole project, or change a function name being called from a pre compiled class or simply change web.xml which is loaded at start up. Of course then hot deploy will not work.
  4. In such a case, stop your remove debug from within eclipse, complete your tasks, run mvn compile install from Terminal 2. Devserver will autodetect.
  5. Mostly, I hardly need to touch the tail running in Terminal 1. Devserver does not tend to need restart.
  6. Unless I am changing web.xml or refactoring, I do not need to run mvn compile install from outside.

My reason for giving list of windows (Eclipse, Terminal 1 and Terminal 2) is just to show that Alt+Tab is actually faster than Shift+F7 from within eclipse. It is subjective and of course up to you.

like image 32
PoojaC20 Avatar answered Oct 04 '22 12:10

PoojaC20