And*_*Dev 3 java google-app-engine intellij-idea maven
我正在浏览 Google App Engine for Java 的“Hello World”教程。当我通过执行以下命令在浏览器中运行应用程序时,一切正常:
mvn appengine:devserver
Run Code Online (Sandbox Code Playgroud)
在我的浏览器中,我刚刚启动:
http://localhost:8080
Run Code Online (Sandbox Code Playgroud)
但是在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>
Run Code Online (Sandbox Code Playgroud)
如何修复此问题以便可以在 Intellij 中运行调试?
您正在使用 Maven 运行开发服务器,因此您需要设置远程调试配置。
您将看到它正在侦听端口 5005,因此您需要确保您的 App Engine 插件部分pom.xml具有相同的端口号:
<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>
Run Code Online (Sandbox Code Playgroud)
您正常启动开发服务器(在端口 8080 或您在 pom 中配置的任何端口上),但现在您可以在代码中放置一个断点,当您触发该代码段时(例如,转到浏览器中的页面),您可以在调试器中单步执行。
| 归档时间: |
|
| 查看次数: |
1337 次 |
| 最近记录: |