【问题标题】:Debugging Google App Engine app in Intellij在 Intellij 中调试 Google App Engine 应用
【发布时间】:2016-07-12 01:48:20
【问题描述】:

我正在学习 Google App Engine for Java 的“Hello World”教程。当我通过执行在浏览器中运行应用程序时,一切正常:

mvn appengine:devserver

在我的浏览器中,我刚刚启动:

http://localhost:8080

但在 Intellij 中,当我运行 Debug 时,浏览器打开但页面无法显示(错误 403)。

我认为问题与 Intellij 中的项目配置方式有关。请参阅我的调试设置的附加屏幕截图:

我不清楚输入 Maven 命令时使用的是哪个应用程序服务器,以及从 Intellij 运行它时使用的是哪个应用程序服务器。 Intellij 似乎确实使用了 Jetty。这是 Intellij 中应用程序服务器设置的快照:

这是 pom.xml 文件:

<?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>

如何解决此问题以便在 Intellij 中运行调试?

【问题讨论】:

    标签: java maven google-app-engine intellij-idea


    【解决方案1】:

    您正在使用 Maven 运行您的开发服务器,因此您需要设置一个 Remote 调试配置。

    • 运行菜单下,选择编辑配置...
    • 点击 + 图标(左上角)添加新配置
    • 选择远程。您应该会看到这些选项

    您将看到它正在侦听端口 5005,因此您需要确保 pom.xml 中的 App Engine 插件部分具有相同端口号的此部分:

    <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>
    

    您可以正常启动开发服务器(在端口 8080 或您在 pom 中配置的任何端口),但现在您可以在代码中放置断点,并在触发该段代码时(例如,转到您的浏览器),您可以在调试器中单步执行。

    【讨论】:

    • 我进行了您指示的更改,但是当我运行调试时,我得到:运行调试本地应用程序引擎时出错:无法打开调试器端口(本地主机:5005):java.net.ConnectException“连接被拒绝”-我需要设置某种权限吗?我在 Mac 上运行它。
    • 您是否有任何类型的防火墙可以阻止它?您的 mvn 输出是否显示类似 Listening for transport dt_socket at address: 5005 的内容?
    • 我怀疑防火墙阻止了它,因为命令 mvn appengine:devserver 有效。但我不确定端口 5005 是否被阻塞。我没有看到任何 Maven 输出,因为我在 IDE 中运行它。
    猜你喜欢
    • 2011-03-06
    • 1970-01-01
    • 1970-01-01
    • 2014-06-14
    • 1970-01-01
    • 1970-01-01
    • 2016-07-19
    • 2012-05-04
    • 2021-04-18
    相关资源
    最近更新 更多