【问题标题】:How to get maven and appengine to do hot reload when developing开发时如何让maven和appengine做热重载
【发布时间】:2018-11-29 19:13:23
【问题描述】:

我正在尝试将基于 Java 的 appengine 用于一个爱好项目,但在开发时我无法让我的应用程序的热重载/交换工作。我已经尝试了几件事,但没有运气。

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project>
  <modelVersion>4.0.0</modelVersion>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>

  <groupId>grocerymonkey</groupId>
  <artifactId>grocerymonkeyapp</artifactId>

  <properties>
    <!-- uncomment if you wish to set your project here project- gcloud is used otherwise -->
    <!-- <app.deploy.project>your-app-id</app.deploy.project> -->
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
    <maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
    <archiveClasses>true</archiveClasses>
  </properties>

  <prerequisites>
    <maven>3.5</maven>
  </prerequisites>

  <dependencies>
    <!-- Compile/runtime dependencies -->
    <dependency>
      <groupId>com.google.appengine</groupId>
      <artifactId>appengine-api-1.0-sdk</artifactId>
      <version>1.9.59</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1.0</version>
      <type>jar</type>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
    </dependency>

    <!-- Test Dependencies -->
    <dependency>
      <groupId>com.google.appengine</groupId>
      <artifactId>appengine-testing</artifactId>
      <version>1.9.59</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>com.google.appengine</groupId>
      <artifactId>appengine-api-stubs</artifactId>
      <version>1.9.59</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.google.appengine</groupId>
      <artifactId>appengine-tools-sdk</artifactId>
      <version>1.9.59</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>com.google.truth</groupId>
      <artifactId>truth</artifactId>
      <version>0.33</version>
      <scope>test</scope>
    </dependency>

    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.mockito</groupId>
      <artifactId>mockito-all</artifactId>
      <version>2.0.2-beta</version>
      <scope>test</scope>
    </dependency>

        <dependency>
            <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
      <version>2.8.5</version>
      <scope>compile</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.codehaus.mojo</groupId>
        <artifactId>versions-maven-plugin</artifactId>
        <version>2.3</version>
        <executions>
          <execution>
            <phase>compile</phase>
            <goals>
              <goal>display-dependency-updates</goal>
              <goal>display-plugin-updates</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <excludes>
            <exclude>javax.servlet:javax.servlet-api</exclude>
            <exclude>com.google.guava:guava</exclude> <!-- avoid android version -->
          </excludes>
        </configuration>
      </plugin>

      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>3.1.0</version>
      </plugin>

      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.6.1</version>
      </plugin>

      <plugin>
        <artifactId>maven-clean-plugin</artifactId>
        <version>3.0.0</version>
      </plugin>

      <plugin>
        <artifactId>maven-install-plugin</artifactId>
        <version>2.5.2</version>
      </plugin>

      <plugin>
        <artifactId>maven-surefire-plugin</artifactId>
        <version>2.20</version>
      </plugin>

      <plugin>
        <artifactId>maven-site-plugin</artifactId>
        <version>3.6</version>
      </plugin>

      <plugin>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.2</version>
      </plugin>

      <plugin>
        <artifactId>maven-deploy-plugin</artifactId>
        <version>3.1</version>
      </plugin>

      <plugin>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
        <executions>
          <execution>
            <id>enforce-maven</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <requireMavenVersion>
                  <version>3.5</version>
                </requireMavenVersion>
                <requirePluginVersions>
                   <message>Best Practice is to always define plugin versions!</message>
                   <banLatest>true</banLatest>
                   <banRelease>true</banRelease>
                   <phases>clean,deploy,verify,appengine:run,appengine:deploy,appengine:update,appengine:devappaserver,site</phases>
                </requirePluginVersions>
              </rules>
            </configuration>
          </execution>
        </executions>
      </plugin>

            <!-- https://cloud.google.com/appengine/docs/standard/java/building-app/environment-setup //-->
            <plugin>
        <groupId>com.google.cloud.tools</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
        <version>1.3.1</version>
      </plugin>

            <plugin>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>9.4.14.v20181114</version>
            </plugin>
    </plugins>
  </build>
</project>

我无法使用 mvh appengine:devserver,当我尝试时收到以下错误消息

在插件中找不到目标“devserver” com.google.cloud.tools:appengine-maven-plugin:1.3.1 可用 目标部署,deployCron,deployDispatch,deployDos,deployIndex, deployQueue, genRepoInfoFile, help, run, stage, start, stop -> [帮助 1]

我已尝试设置 fullscanseconds=5 或更少,但无论我更改 HTML 文件还是 servlet,我仍然需要停止服务器并使用 mvn appengine:run 手动重新启动它。这使得在本地开发任何东西都非常非常耗时。我也尝试过使用 jetty,但是失败了,然后我意识到 appengine 在本地测试时显然是在 jetty 上运行的。

当我在开发时尝试使用码头时,由于安全限制,我遇到了问题。

web.xml

<security-constraint>
            <web-resource-collection>
                <url-pattern>/*</url-pattern>
            </web-resource-collection>
            <user-data-constraint>
                <transport-guarantee>CONFIDENTIAL</transport-guarantee>
            </user-data-constraint>
        </security-constraint>

码头给了我一个 403 错误信息。

【问题讨论】:

    标签: java maven google-app-engine


    【解决方案1】:

    您提出了三个不同的问题:App Engine 上的热重载、使用 mvh appengine:devserver 时的部署问题和 Jetty 403 错误消息。

    关于热重载,只有在 Java 中的某些情况下才有可能,正如 Patrice (googler) 在this post 中所解释的那样。

    关于 Jetty,403 错误大多与权限有关,如wikipedia 所述:

    请求有效,但服务器拒绝操作。用户 可能没有资源的必要权限,或者可能需要 某种帐户。

    关于 mvn 开发环境,仅基于您的pom.xml 很难评估,但基于此SO post,我将审查groupIds,目标和参数描述here(您不应该使用appengine -web.xml 而不是 web.xml?) 和Apache Maven 的官方文档。

    【讨论】:

      猜你喜欢
      • 2019-04-24
      • 2015-02-16
      • 2018-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-19
      • 2022-08-24
      相关资源
      最近更新 更多