Appengine Maven插件 - 端点目标 - 启用.discovery文件的过滤

时间:2014-12-03 14:25:23

标签: google-app-engine maven google-cloud-endpoints maven-war-plugin

关注this guide后,我在Maven项目中实施了Google Cloud Endpoints

这是我的pom.xml的属性

<properties>
    <appengine.app.id>xxxxxxxx</appengine.app.id>
</properties>

这是我在pom.xml中的maven-war-plugin配置

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <version>2.4</version>
    <configuration>

        <!-- http://maven.apache.org/plugins/maven-war-plugin/examples/adding-filtering-webresources.html -->
        <!-- To prevent corrupting your binary files when filtering is enabled, you can configure a list of file extensions that will not be filtered. -->
        <nonFilteredFileExtensions>
            <nonFilteredFileExtension>p12</nonFilteredFileExtension>
        </nonFilteredFileExtensions>

        <archiveClasses>true</archiveClasses>

        <!-- https://cloud.google.com/appengine/docs/java/tools/maven#cloud_endpoints_goals -->
        <webXml>${project.build.directory}/generated-sources/appengine-endpoints/WEB-INF/web.xml</webXml>

        <webResources>

            <!-- in order to interpolate version from pom into appengine-web.xml -->
            <resource>
                <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                <filtering>true</filtering>
                <targetPath>WEB-INF</targetPath>
            </resource>

            <resource>
                <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
                <includes>
                    <include>WEB-INF/*.discovery</include>
                    <include>WEB-INF/*.api</include>
                </includes>
            </resource>

        </webResources>

    </configuration>
</plugin>

这是我的appengine-web.xml文件的头部

<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">

    <application>${appengine.app.id}</application>
    <version>${project.version}</version>
    ....
</appengine-web-app>

以下是生成的数据

enter image description here

问题 .discovery 文件在创建过程中无法解析maven属性

的MyStore-V1-rest.discovery

"protocol": "rest",
"baseUrl": "https://${appengine.app.id}.appspot.com/_ah/api/mystore/v1/",
"basePath": "/_ah/api/mystore/v1/",
"rootUrl": "https://${appengine.app.id}.appspot.com/_ah/api/",
"servicePath": "mystore/v1/",

的MyStore-V1-rpc.discovery

protocol": "rpc",
"rootUrl": "https://${appengine.app.id}.appspot.com/_ah/api/",
"rpcUrl": "https://${appengine.app.id}.appspot.com/_ah/api/rpc",
"rpcPath": "/_ah/api/rpc",

为什么不像WEB-INF文件夹中保存的任何其他文件那样过滤这些文件?

我在许多文件中使用Maven变量(在WEB-INF父文件夹下),并且值被替换为没有问题。

如何调整配置以允许在 .discovery 文件上进行过滤?

我认为(在lib生成期间)从appengine-web.xml获取application值而不解析该值,并且在Maven构建期间,不应用过滤。

我已经尝试将<filtering>true</filtering>添加到资源配置中,但没有成功

---编辑25/01/2014 ---

在收到一些建议之后,我需要澄清我在原帖中忘记写的内容。

问题与endpoints_get_discovery_doc

有关

以下是Maven目标的日志

API Discovery Document written to ..\target\generated-sources\appengine-endpoints\WEB-INF/mystore-v3-rpc.discovery
API Discovery Document written to ..\target\generated-sources\appengine-endpoints\WEB-INF/mystore-androidtest-rpc.discovery

文件\target\generated-sources\appengine-endpoints\WEB-INF/mystore-v3-rpc.discovery由端点目标生成,不会被过滤。

即使使用过滤属性

<resource>
    <directory>${project.build.directory}/generated-sources/appengine-endpoints</directory>
    <filtering>true</filtering>
    <includes>
        <include>WEB-INF/*.discovery</include>
        <include>WEB-INF/*.api</include>
    </includes>
</resource>

不会过滤生成的文件。

也许问题是,如果文件直接写在${project.build.directory}/generated-sources/appengine-endpoints文件夹中,文件不会被过滤?

2 个答案:

答案 0 :(得分:2)

    <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>
                    <!-- in order to interpolate version from pom into appengine-web.xml -->
                    <resource>
                        <directory>${basedir}/src/main/webapp/WEB-INF</directory>
                        <filtering>true</filtering>
                        <targetPath>WEB-INF</targetPath>
                    </resource>
                    <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>
                        <filtering>true</filtering>
                    </resource>
                </webResources>
            </configuration>
        </plugin>

答案 1 :(得分:0)

<!--User the below Line, I also had the same problem that I solved using Note: <version>${app.version}</version><appId>${app.id}</appId> folow as per your configuration --!>                                
    <plugin>
    <groupId>com.google.appengine</groupId>
            <artifactId>appengine-maven-plugin</artifactId>
            <version>${appengine.version}</version>
            <configuration>
                <enableJarClasses>false</enableJarClasses>
                <version>${app.version}</version>
                <appId>${app.id}</appId>
                <!-- 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 remote 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>