Is it possible to use appengine modules and and cloud endpoints?

685 views Asked by At

Using appengine modules implies creating dynamic web application instead of the usual appengine web application project. Cloud endpoints work well with the usual appengine Web Application projects, but these do not support appengine modules.

The problem is that if I try to generate cloud endpoint client library on a Dynamic Web Application, I get an error "Not an App Engine project".

Is there any way to get a Dynamic Web Application to be recognized as an App Engine project so that cloud endpoint client libraries can be generated on it?

2

There are 2 answers

0
Kidogo On BEST ANSWER

The solution to this case is within François POYER answer, but here is a version with no maven assumed.

If you are using WTP to create and manage your appengine application and EAR:

  1. Ensure you are in the Java EE perspective
  2. Right click on your cloud endpoints project => "Google App Engine WTP" => "Generate Cloud Endpoint Client Library"

If you do not see Google App Engine WTP and you only see "Google", its likely you have not selected the Java EE perspective.

You do not have to use maven for this, simply use WTP to create and manage your EARs and appengine applications.

1
François POYER On

Currently working on the same problem, I think I have found a solution with the following setup (using maven for a java project):

In the project-root pom.xml: defines a few common values (like the appengine version you're using), a pom packaging and your modules, especially an EAR one:

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

The pom.xml of the EAR module should have of course EAR packaging but also "war" typed dependencies on the other modules and the "unpack types" option of the maven-ear plugin set to "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>

Finally, the "cloud-endpoints" pom.xml should be configured as a basic cloud endpoints webapp project with "war" packaging:

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

Building this project, you should be able to generate your cloud-endpoints client librariy through Eclipse: right click on the "cloud-endpoints" project => "Google App Engine WTP" => "Generate Cloud Endpoint Client Library" will generate everything needed in myproject-cloud-endpoints/endpoint-libs/.

Hope that helps!