使用appengine模块意味着创建动态Web应用程序而不是通常的appengine Web应用程序项目。云端点与通常的appengine Web应用程序项目配合良好,但这些项目不支持appengine模块。
问题是,如果我尝试在动态Web应用程序上生成云端点客户端库,我会收到错误"而不是App Engine项目"。
有没有办法让动态Web应用程序被识别为App Engine项目,以便可以在其上生成云端点客户端库?
答案 0 :(得分:0)
目前处理同样的问题,我想我已经找到了一个解决方案,其中包含以下设置(使用maven进行java项目):
在project-root 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>
EAR模块的pom.xml当然应该包含EAR包装,但也包括#34; war&#34;对其他模块的类型依赖关系以及&#34;解包类型&#34; maven-ear插件的选项设置为&#34; war&#34;:
<?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-ear</artifactId>
<version>1.0</version>
<packaging>ear</packaging>
<name>myproject-ear</name>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-ear-plugin</artifactId>
<version>2.9</version>
<configuration>
<version>5</version>
<defaultLibBundleDir>lib</defaultLibBundleDir>
<unpackTypes>war</unpackTypes>
<applicationXml>${project.basedir}/src/main/application/META-INF/maven-application.xml</applicationXml>
</configuration>
</plugin>
<plugin>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.target.version}</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>myproject-cloud-endpoints</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>myproject-backend</artifactId>
<version>1.0</version>
<type>war</type>
</dependency>
</dependencies>
<properties/>
</project>
最后,&#34;云端点&#34;应该将pom.xml配置为基本的云端点webapp项目,使用&#34; war&#34;包装
<?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>
构建此项目,您应该能够通过Eclipse生成您的云端点客户端库管理程序:右键单击&#34; cloud-endpoints&#34; project =&gt; &#34; Google App Engine WTP &#34; =&GT; &#34;生成Cloud Endpoint客户端库&#34;将生成myproject-cloud-endpoints/endpoint-libs/
中所需的所有内容。
希望有所帮助!
答案 1 :(得分:0)
这个案例的解决方案是在FrançoisPOYER的回答中,但这里是一个没有maven假设的版本。
如果您使用WTP创建和管理您的appengine应用程序和EAR:
如果您没有看到 Google App Engine WTP 而您只看到“Google”,则可能您没有选择Java EE视角。
您不必为此使用maven,只需使用WTP创建和管理您的EAR和appengine应用程序。