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?
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.
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
- If you already have source code, keep it somewhere else and generate a skeleton using mvn appengine command.
- Run the first cut with a simple Hello World using only maven and terminal and mvn appengine:devserver command.
- Once done, generate the eclipse project.
- 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.
- The step above will create three projects, top level, ear and war each with pom.xml - It's OK.
- In eclipse, provide the output directory as war/target directory. This is the step which makes it possible to hot deploy.
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>
Notice the suspend=n.
- 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.
- 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.- 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
- Open another terminal, Terminal 2 in the war directory and keep it open in order to run
mvn compile install
when you need to.- 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.
- 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.
- In such a case, stop your remove debug from within eclipse, complete your tasks, run
mvn compile install
from Terminal 2. Devserver will autodetect.- Mostly, I hardly need to touch the tail running in Terminal 1. Devserver does not tend to need restart.
- 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With