简体   繁体   中英

Debugging Google App Engine app in Intellij

I'm going through the "Hello World" tutorial from Google App Engine for Java. Everything works fine when I run the app in my browser by executing:

mvn appengine:devserver

In my browser I just launch:

http://localhost:8080

But in Intellij, when I run Debug, the browser opens but the page cannot be displayed (Error 403).

I believe the problem has to do with the way the project is configured in Intellij. See the attached screenshot of my Debug settings:

调试设置

It isn't clear to me what application server the Maven command is using when I type it in and which one is used when I run it from Intellij. The Intellij does appear to use Jetty. Here is a snapshot of the Application Server settings in Intellij:

应用服务器设置

Here's the pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright 2015 Google Inc. All Rights Reserved.

 Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License.
 You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software
 distributed under the License is distributed on an "AS IS" BASIS,
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <groupId>com.example.appengine</groupId>
    <artifactId>appengine-helloworld</artifactId>
    <!-- Parent POM defines ${appengine.sdk.version} (updates frequently). -->
    <parent>
        <groupId>com.google.cloud</groupId>
        <artifactId>doc-samples</artifactId>
        <version>1.0.0</version>
        <relativePath>../..</relativePath>
    </parent>
    <dependencies>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <type>jar</type>
            <scope>provided</scope>
        </dependency>
    </dependencies>
    <build>
        <!-- for hot reload of the web application -->
        <outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <version>3.3</version>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${appengine.sdk.version}</version>
            </plugin>
        </plugins>
    </build>
</project>

How can I fix this so that I can run Debug in Intellij?

You are running your dev server with Maven, so you need to setup a Remote debug configuration.

  • Under the Run menu, select Edit configurations...
  • Click the + icon (top left) to add a new configuration
  • Select Remote . You should see these options

App Engine的远程调试选项

You will see it is listening on port 5005 so you need to make sure the App Engine plugin section in your pom.xml has this section with the same port number:

<plugin>
    <groupId>com.google.appengine</groupId>
    <artifactId>appengine-maven-plugin</artifactId>
    <version>${appengine.sdk.version}</version>
    <configuration>
        <-- other config stuff here -->
        <jvmFlags>
            <jvmFlag>-Xdebug</jvmFlag>
            <jvmFlag>-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=5005</jvmFlag>
        </jvmFlags>
    </configuration>
</plugin>

You start the dev server as normal (on port 8080 or whatever you configured in your pom), but now you can put a breakpoint in your code and when you trigger that piece of code (eg, going to the page in your browser), you can step through in the debugger.

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