2016-03-24 37 views
1

我正在閱讀Google App Engine for Java中的「Hello World」教程。一切工作正常,當我通過執行運行在瀏覽器中的應用:在Intellij中調試Google App Engine應用程序

mvn appengine:devserver 

在我的瀏覽器我剛剛推出:

http://localhost:8080 

但在的IntelliJ,當我運行調試,在瀏覽器中打開,但網頁無法顯示(錯誤403)。

我認爲問題與Intellij中項目的配置方式有關。見我的調試設置附截圖:

Debug settings

這是我不太清楚,當我鍵入它,當我從的IntelliJ運行哪一個使用Maven的命令正在使用什麼應用程序服務器。 Intellij似乎使用Jetty。這是在的IntelliJ的應用程序服務器設置的快照:

App Server Settings

這裏的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調試?

回答

3

您正在使用Maven運行您的開發服務器,因此您需要設置遠程調試配置。

  • 運行菜單,選擇編輯配置...
  • 單擊+圖標(左上)添加新的配置
  • 選擇遠程。您應該看到這些選項

Remote debug options for App Engine

你會看到它正在偵聽端口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> 

正常情況下啓動開發服務器(在端口8080或任何你在你的pom配置),但現在你可以在你的代碼中放置一個斷點,當你觸發這段代碼(例如,進入頁面在你的瀏覽器中),你可以在調試器中一步一步完成。

+0

我做了你指出的更改,但是當我運行調試時,我得到:運行調試本地應用程序引擎時出錯:無法打開調試器端口(localhost:5005):java.net.ConnectException「連接被拒絕」 - 是否需要安裝某種權限?我在Mac上運行這個。 – AndroidDev

+0

你有沒有可能阻擋它的防火牆?你的mvn輸出是否顯示類似於'在地址:5005'偵聽傳輸dt_socket? – tx802

+0

我懷疑防火牆正在阻止它,因爲命令mvn appengine:devserver起作用。但我不確定端口5005是否被阻塞。我沒有看到任何Maven輸出,因爲我在IDE中運行它。 – AndroidDev

相關問題