簡體   English   中英

是否可以使用appengine模塊和雲終端?

[英]Is it possible to use appengine modules and and cloud endpoints?

使用appengine模塊意味着創建動態Web應用程序,而不是通常的appengine Web應用程序項目。 雲端點可以與常用的appengine Web應用程序項目一起很好地工作,但是這些端點不支持appengine模塊。

問題是,如果我嘗試在動態Web應用程序上生成雲終結點客戶端庫,則會收到錯誤“不是App Engine項目”。

有什么方法可以將動態Web應用程序識別為App Engine項目,以便可以在其上生成雲終結點客戶端庫?

目前正在解決相同的問題,我想我已經找到了以下設置的解決方案(將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>

EAR模塊的pom.xml當然應該具有EAR打包,還應該具有對其他模塊的“ war”類型依賴關系,並且maven-ear插件的“ unpack types”選項設置為“ war”:

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

最后,應將“ 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>

構建此項目,您應該能夠通過Eclipse生成雲端點客戶端庫:右鍵單擊“ cloud-endpoints”項目=>“ Google App Engine WTP ” =>“生成雲端點客戶端庫”將生成所需的一切在myproject-cloud-endpoints/endpoint-libs/

希望有幫助!

FrançoisPOYER的回答是針對這種情況的解決方案,但這是不帶Maven的版本。

如果您使用WTP創建和管理您的Appengine應用程序和EAR:

  1. 確保您在Java EE透視圖中
  2. 右鍵單擊您的雲終結點項目=>“ Google App Engine WTP ” =>“生成雲終結點客戶端庫”

如果您沒有看到Google App Engine WTP,而僅看到“ Google”,則可能您沒有選擇Java EE透視圖。

您不必為此使用maven,只需使用WTP即可創建和管理EAR和appengine應用程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM