Dev workflow for app engine + modules + maven

2019-06-16 11:44发布

We recently converted our app engine project into modules as per the structure below. The problem with this new dev workflow is that we have to rebuild the EAR on every change and relaunch the app engine local dev server. This makes us loose 30s to a minute every time we make a change to the code and want to test it.

/commons
 -pom.xml
/model
 -pom.xml
/webapp //app engine module
 -pom.xml
/apis //app engine module
 -pom.xml
/ear
 -pom.xml
pom.xml //main (parent) project pom

In our previous workflow, with the monolithic app, we could use app engine's hot reload functionality, where modifying code in an IDE (e.g. eclipse) would be picked up automatically.

What do you guys recommend as the best maven config and/or dev workflow in this case? Ideally, a change in any of the modules would not require a full rebuild of the project.

1条回答
爱情/是我丢掉的垃圾
2楼-- · 2019-06-16 11:53

I am using a similar structure with a small difference. The top level directory has war and ear and then they contain their specific pom.xml. I use Eclipse for debugging, and I am able to hot deploy "most of the time" and I am not using Eclipse plugin, which (I understand) is what you want.

Directory Structure

.
|-- pom.xml
|-- README.md
|-- my-ear
|   |-- devpid
|   |-- pom.xml
|   `-- src
|       `-- main
|           `-- application
|               `-- META-INF
`-- my-war
    |-- build
    |   `-- classes
    |       |-- main
    |       |   |-- java
    |       |   `-- webapp
    |       `-- test
    |           `-- java
    |-- pom.xml
    `-- src
        |-- main
        |   |-- java
        |   |   `-- com
        |   `-- webapp
        |       |-- css
        |       |-- favicon.ico
        |       |-- index.html
        |       |-- js
        |       |-- test.html
        |       `-- WEB-INF
        `-- test
            `-- java

Tools

  • Eclipse Luna without Google App Engine Plugin (or SDK)
  • Maven 3.2.1
  • Google App Engine SDK 1.9.6

Dev Workflow

  1. If you already have source code, keep it somewhere else and generate a skeleton using mvn appengine command.
  2. Run the first cut with a simple Hello World using only maven and terminal and mvn appengine:devserver command.
  3. Once done, generate the eclipse project.
  4. Import the eclipse project as a Maven project. It will see the jars via Maven. I won't have written this answer before Luna as it required too many tweaks. In Luna, this works automatically.
  5. The step above will create three projects, top level, ear and war each with pom.xml - It's OK.
  6. In eclipse, provide the output directory as war/target directory. This is the step which makes it possible to hot deploy.
  7. In maven ear/pom.xml, add xArgs to appengine plugin for running in debug mode.

    <plugin>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-maven-plugin</artifactId>
        <version>${appengine.target.version}</version>
        <configuration>
            <jvmFlags>
            <jvmFlag>-Xdebug</jvmFlag>
                <jvmFlag>-Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n</jvmFlag>
            </jvmFlags>
            <disableUpdateCheck>true</disableUpdateCheck>
        </configuration>
    </plugin>
    
  8. Notice the suspend=n.

  9. Run the app engine from outside eclipse using mvn appengine:devserver from the ear directory. I use this command: mvn appengine:devserver > ~/.logs/.appengine.devserver.logs & echo $! > devpid Let's call this Terminal 1.
  10. An advantage of this method is that your console is not captured by Eclipse, so you are free to use a tool of your choice to view it, like multitail etc. I use this simple tail command: tail -f ~/.logs/.appengine.devserver.logs | sed 's/INFO/^[[0;34m&^[[0m/g;s/ERROR/^[[0;31m&^[[0m/g;s/WARN\|WARNING/^[[0;35m&^[[0m/g;s/SEVERE\|FATAL/^[[0;31;47m&^[[0m/g' The above is a difficult to type command. Every instance of ^[ is actually Ctrl+V Esc - it is worth the effort of typing it once. But this is of course subjective and up to you.
  11. In Eclipse, create a Debug Profile for your project under Remote Java Application - select the war project and socket attach options. This step is available on the internet at many places, here is an image nevertheless Debug Config, Remote Application, War Socket Attach

  12. Open another terminal, Terminal 2 in the war directory and keep it open in order to run mvn compile install when you need to.

  13. You are good to go. You should be able to integrate your source code by just pasting it at the right place. You should also be able to use standard debugging techniques. Eclipse will compile at the right location and devserver will detect it all right. If Eclipse throws a warning, ignore it.
  14. This works most of the time. Sometimes, you save something that breaks compilation of the whole project, or change a function name being called from a pre compiled class or simply change web.xml which is loaded at start up. Of course then hot deploy will not work.
  15. In such a case, stop your remove debug from within eclipse, complete your tasks, run mvn compile install from Terminal 2. Devserver will autodetect.
  16. Mostly, I hardly need to touch the tail running in Terminal 1. Devserver does not tend to need restart.
  17. Unless I am changing web.xml or refactoring, I do not need to run mvn compile install from outside.

My reason for giving list of windows (Eclipse, Terminal 1 and Terminal 2) is just to show that Alt+Tab is actually faster than Shift+F7 from within eclipse. It is subjective and of course up to you.

查看更多
登录 后发表回答