Is there any way to trigger the Maven Appengine De

2019-04-22 21:12发布

The most recent version of the maven plugin has enabled updating of code every 5s, which is a great improvement. But unless I am configuring this wrong, it doesn't seem to pick up static file changes such as work in progress Javascript connecting to the appengine code.
Is there any way to alter this behavior or do I just need to wait for a new release?

3条回答
一夜七次
2楼-- · 2019-04-22 21:48

Automatic updates cannot be done using appending devserver alone right now. Strictly speaking, we need to wait.

But you can achieve the effect of seamless html/js/css/etc update, hot java code replacement, etc. with the configuration below.

  1. Configure Apache httpd or Nginx to serve static code directly from your war-source and route to app engine for servlets. In my case, all the html are directly accessible from webapp directory and servlets are called via /sim/. Using nginx and 7070 port, my working nginx config looks like:

    server {
      listen 7070;
    
      root /home/pchauhan/Projects/my-company/my-mvn-gae-project/my-mvn-gae-project-war/src/main/webapp;
    
      location /sim/ {
            proxy_pass http://localhost:8080/sim/;
      }
    }
    

Use this documentation of nginx, for more configurations.

Configure Eclipse and GAE separately.

  1. Now, you can directly make changes to source and get them on refresh, both for html (via nginx) and servlets (via devserver).
  2. Add this webapp folder to your Chrome Dev Tools, Sources Workspace and life will be easier. Small changes can directly be saved from chrome to src via ctrl

Please note, that while this is great, you should test your app once solely on 8080 (devserver port) before uploading, just in case there is a bug in maven config and target is not being created/served correctly.

Alternate Idea for syncing: If you do not want to use nginx/httpd for some reason, you can add target...webapp to chrome workspace, work directly there for seamless updt and then use lsyncd to sync target back to src. I haven't tried it yet, but looks feasible, albeit a bit risky.

查看更多
三岁会撩人
3楼-- · 2019-04-22 22:05

So far, best way i found was configuring below entries in pom.xml. This will build automatically your static files and reflects on the page.

<plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <version>1.7</version>
            <executions>
                <execution>
                    <phase>process-classes</phase>
                    <goals>
                        <goal>run</goal>
                    </goals>
                    <configuration>
                        <target>
                            <property name="target.webapp.dir"
                                value="${project.build.directory}/${project.build.finalName}" />
                            <property name="src.webapp.dir" value="${basedir}/src/main/webapp" />

                            <sync verbose="true" todir="${target.webapp.dir}"
                                includeEmptyDirs="true">
                                <fileset dir="${src.webapp.dir}" />
                                <preserveintarget>
                                    <include name="WEB-INF/lib/**" />
                                    <include name="WEB-INF/classes/**" />
                                    <include name="WEB-INF/appengine-generated/**" />
                                </preserveintarget>
                            </sync>

                            <!-- <sync verbose="true" todir="${target.webapp.dir}/WEB-INF/classes"> 
                                <fileset dir="${basedir}/target/classes" /> </sync> -->

                        </target>
                    </configuration>
                </execution>
            </executions>
        </plugin>

And another entry after

<pluginManagement>
        <plugins>
            <!-- This plugin's configuration is used to store Eclipse m2e settings 
                only. It has no influence on the Maven build itself. -->
            <plugin>
                <groupId>org.eclipse.m2e</groupId>
                <artifactId>lifecycle-mapping</artifactId>
                <version>1.0.0</version>
                <configuration>
                    <lifecycleMappingMetadata>
                        <pluginExecutions>
                            <pluginExecution>
                                <pluginExecutionFilter>
                                    <groupId>org.apache.maven.plugins</groupId>
                                    <artifactId>maven-antrun-plugin</artifactId>
                                    <versionRange>[1.6,)</versionRange>
                                    <goals>
                                        <goal>run</goal>
                                    </goals>
                                </pluginExecutionFilter>
                                <action>
                                    <execute>
                                        <runOnIncremental>true</runOnIncremental>
                                    </execute>
                                </action>
                            </pluginExecution>
                        </pluginExecutions>
                    </lifecycleMappingMetadata>
                </configuration>
            </plugin>
        </plugins>
    </pluginManagement>

This is working fine. As soon as any static files changed and saved, it got reflected on the page.

查看更多
男人必须洒脱
4楼-- · 2019-04-22 22:08

Like PoojaC20, I have also not been able to get this working with devserver alone but I ended up with a different workaround which I thought I'd share in case others found it helpful.

I now host my development static files outside of the GAE devserver by using grunt-serve. This allows a large number of advantages including:

  1. Automatic page refresh when static files have changed - don't even need to press the refresh button.
  2. Automatic conversion of advanced CSS such as LESS
  3. Automatic conversion of javascript-compileable languages such as CoffeeScript
  4. Mechanism for minification and CDN-ification when development is done.

The most profound implication of the above is that I have needed to move away from session based authentication to OAuth or OpenID Connect based authentication systems and to make all of my web service calls CORS compatible. This is some work, but it too has one very profound advantage:

  1. Once your web sever has moved to OpenID Connect based authentication, it can now connect identically to native (e.g. mobile) client or web based clients!
查看更多
登录 后发表回答