Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any way to trigger the Maven Appengine Devserver to auto-refresh static files?

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?

like image 565
OverclockedTim Avatar asked Jan 25 '14 00:01

OverclockedTim


2 Answers

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.

like image 129
PoojaC20 Avatar answered Nov 06 '22 09:11

PoojaC20


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.

like image 20
pra Avatar answered Nov 06 '22 09:11

pra