Java 是否可以使用appengine模块和云端点?

Java 是否可以使用appengine模块和云端点?,java,google-app-engine,gae-module,app-engine-modules,Java,Google App Engine,Gae Module,App Engine Modules,使用appengine模块意味着创建动态web应用程序,而不是通常的appengine web应用程序项目。云端点与通常的appengine Web应用程序项目配合得很好,但这些项目不支持appengine模块 问题是,如果我试图在动态Web应用程序上生成云端点客户端库,我会得到一个错误“不是应用程序引擎项目” 有没有办法将动态Web应用程序识别为应用程序引擎项目,以便在其上生成云端点客户端库?目前正在处理同一问题,我想我已经找到了以下设置的解决方案(将maven用于java项目): 在项目根p

使用appengine模块意味着创建动态web应用程序,而不是通常的appengine web应用程序项目。云端点与通常的appengine Web应用程序项目配合得很好,但这些项目不支持appengine模块

问题是,如果我试图在动态Web应用程序上生成云端点客户端库,我会得到一个错误“不是应用程序引擎项目”


有没有办法将动态Web应用程序识别为应用程序引擎项目,以便在其上生成云端点客户端库?

目前正在处理同一问题,我想我已经找到了以下设置的解决方案(将maven用于java项目):

在项目根pom.xml中:定义一些常见值(如您正在使用的appengine版本)、一个
pom
打包和您的模块,尤其是EAR模块:

<?xml version="1.0" encoding="UTF-8"?>
<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>

<groupId>com.example</groupId>
<artifactId>myproject-root</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
<name>myproject-root</name>

<properties>
    <appengine.app.version>1</appengine.app.version>
    <appengine.target.version>1.9.11</appengine.target.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<modules>
    <module>myproject-ear</module>
    <module>myproject-cloud-endpoints</module>
    <module>myproject-backend</module>
</modules>

</project>

4.0.0
com.example
myproject根目录
1
聚甲醛
myproject根目录
1.
1.9.11
UTF-8
我的耳朵项目
myproject云端点
myproject后端
EAR模块的pom.xml当然应该具有EAR封装,但也应该具有对其他模块的“war”类型依赖关系,并且maven EAR插件的“unpack types”选项设置为“war”:


4.0.0
com.example
myproject根目录
1
com.example
我的耳朵项目
1
耳朵
我的耳朵项目
org.apache.maven.plugins
maven编译器插件
2.5.1
1.7
1.7
org.apache.maven.plugins
maven耳朵插件
2.9
5.
解放党
战争
${project.basedir}/src/main/application/META-INF/maven-application.xml
com.google.appengine
appengine maven插件
${appengine.target.version}
com.example
myproject云端点
1
战争
com.example
myproject后端
1
战争
最后,“cloud endpoints”pom.xml应配置为具有“war”包装的基本云端点webapp项目:

<?xml version="1.0" encoding="UTF-8"?>
<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>

<parent>
    <groupId>com.example</groupId>
    <artifactId>myproject-root</artifactId>
    <version>1.0</version>
</parent>

<groupId>com.example</groupId>
<artifactId>myproject-cloud-endpoints</artifactId>
<version>1.0</version>
<packaging>war</packaging>

<name>myproject-cloud-endpoints</name>

<dependencies>
    <!-- Compile/runtime dependencies -->
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>${appengine.target.version}</version>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-endpoints</artifactId>
        <version>${appengine.target.version}</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>
</dependencies>


<build>
    <!-- for hot reload of the web application in devserver-->
    <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.1</version>
            <executions>
                <execution>
                    <phase>compile</phase>
                    <goals>
                        <goal>display-dependency-updates</goal>
                        <goal>display-plugin-updates</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <version>3.1</version>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-war-plugin</artifactId>
            <version>2.4</version>
            <configuration>
                <webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>
                <webResources>
                    <resource>
                        <!-- this is relative to the pom.xml directory -->
                        <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
                        <!-- the list has a default value of ** -->
                        <includes>
                            <include>WEB-INF/*.discovery</include>
                            <include>WEB-INF/*.api</include>
                        </includes>
                    </resource>
                </webResources>
            </configuration>
        </plugin>
        <plugin>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>${appengine.target.version}</version>
            <configuration>
                <enableJarClasses>false</enableJarClasses>
                <!-- Comment in the below snippet to bind to all IPs instead of just localhost -->
                <!-- address>0.0.0.0</address>
                <port>8080</port -->
                <!-- Comment in the below snippet to enable local debugging with a remove debugger
                     like those included with Eclipse or IntelliJ -->
                <!-- jvmFlags>
                  <jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
                </jvmFlags -->
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>endpoints_get_discovery_doc</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

4.0.0
com.example
myproject根目录
1
com.example
myproject云端点
1
战争
myproject云端点
com.google.appengine
appengine-api-1.0-sdk
${appengine.target.version}
com.google.appengine
appengine端点
${appengine.target.version}
javax.servlet
servlet api
2.5
假如
javax.inject
javax.inject
1.
${project.build.directory}/${project.build.finalName}/WEB-INF/classes
org.codehaus.mojo
版本maven插件
2.1
编译
显示依赖项更新
显示插件更新
org.apache.maven.plugins
3.1
maven编译器插件
1.7
1.7
org.apache.maven.plugins
maven战争插件
2.4
${project.build.directory}/generated sources/appengine endpoints/WEB-INF/WEB.xml
${project.build.directory}/generated sources/appengine endpoints
WEB-INF/*.discovery
WEB-INF/*.api
com.google.appengine
appengine maven插件
${appengine.target.version}
假的
端点\u获取\u发现\u文档

构建此项目时,您应该能够通过Eclipse生成云端点客户端库:右键单击“云端点”项目=>“Google App Engine WTP”=>“生成云端点客户端库”将生成
myproject云端点/Endpoint libs/
中所需的所有内容

希望有帮助

这个案例的解决方案在弗朗索瓦·波耶的回答中,但这里是一个没有假设maven的版本

如果您使用WTP创建和管理appengine应用程序和EAR:

  • 确保您处于JavaEE透视图中
  • 右键单击云端点项目=>“谷歌应用程序引擎WTP”=>“生成云端点客户端库”
  • 如果您没有看到谷歌应用程序引擎WTP,而只看到“谷歌”,那么很可能您没有选择JavaEE透视图


    您不必为此使用maven,只需使用WTP创建和管理您的EAR和appengine应用程序即可。

    是否要共享任何文件?pom.xml、WEB-INF/WEB.xml、WEB-INF/dispatch.xml和“mvn清理”、“mvn appengine:endpoints\u get\u discovery\u doc”、“mvn安装”的结果右键单击“cloud endpoints”项目=>“Google App Engine WTP”=>“生成云端点客户端库”是使用WTPThank you创建应用程序时的解决方案。实际上,右键点击“云端点”项目=>“谷歌应用程序引擎WTP”=>“生成云端点客户端库”就是答案。即使在使用WTP和无maven的情况下也能工作
    <?xml version="1.0" encoding="UTF-8"?>
    <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>
    
    <parent>
        <groupId>com.example</groupId>
        <artifactId>myproject-root</artifactId>
        <version>1.0</version>
    </parent>
    
    <groupId>com.example</groupId>
    <artifactId>myproject-cloud-endpoints</artifactId>
    <version>1.0</version>
    <packaging>war</packaging>
    
    <name>myproject-cloud-endpoints</name>
    
    <dependencies>
        <!-- Compile/runtime dependencies -->
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-api-1.0-sdk</artifactId>
            <version>${appengine.target.version}</version>
        </dependency>
        <dependency>
            <groupId>com.google.appengine</groupId>
            <artifactId>appengine-endpoints</artifactId>
            <version>${appengine.target.version}</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.5</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.inject</groupId>
            <artifactId>javax.inject</artifactId>
            <version>1</version>
        </dependency>
    </dependencies>
    
    
    <build>
        <!-- for hot reload of the web application in devserver-->
        <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.1</version>
                <executions>
                    <execution>
                        <phase>compile</phase>
                        <goals>
                            <goal>display-dependency-updates</goal>
                            <goal>display-plugin-updates</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <version>3.1</version>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-war-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>
                    <webResources>
                        <resource>
                            <!-- this is relative to the pom.xml directory -->
                            <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
                            <!-- the list has a default value of ** -->
                            <includes>
                                <include>WEB-INF/*.discovery</include>
                                <include>WEB-INF/*.api</include>
                            </includes>
                        </resource>
                    </webResources>
                </configuration>
            </plugin>
            <plugin>
                <groupId>com.google.appengine</groupId>
                <artifactId>appengine-maven-plugin</artifactId>
                <version>${appengine.target.version}</version>
                <configuration>
                    <enableJarClasses>false</enableJarClasses>
                    <!-- Comment in the below snippet to bind to all IPs instead of just localhost -->
                    <!-- address>0.0.0.0</address>
                    <port>8080</port -->
                    <!-- Comment in the below snippet to enable local debugging with a remove debugger
                         like those included with Eclipse or IntelliJ -->
                    <!-- jvmFlags>
                      <jvmFlag>-agentlib:jdwp=transport=dt_socket,address=8000,server=y,suspend=n</jvmFlag>
                    </jvmFlags -->
                </configuration>
                <executions>
                    <execution>
                        <goals>
                            <goal>endpoints_get_discovery_doc</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>