代码之家  ›  专栏  ›  技术社区  ›  Aun

如何让maven和appengine在开发时进行热重新加载

  •  0
  • Aun  · 技术社区  · 8 年前

    我正试图将基于Java的appengine用于一个爱好项目,但在开发应用程序时,我无法使我的应用程序的热重新加载/交换正常工作。我试过好几种方法,但没有成功。

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

    com.google.cloud.tools:appenginemaven插件:1.3.1 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>
    

    1 回复  |  直到 8 年前
        1
  •  1
  •   Rubén C. Frank van Puffelen    8 年前

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

    关于Jetty,403个错误主要与权限有关,如中所述 wikipedia :

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

    关于mvn开发环境,仅基于您的 pom.xml 但基于此, SO post ,我会回顾 groupIds ,描述的目标和参数 here (您不应该使用appengine-web.xml而不是web.xml吗?) Apache Maven