Deploy to Google App Engine (GAE)

555 views
Skip to first unread message

Craig Mitchell

unread,
Dec 17, 2023, 12:20:56 AM12/17/23
to GWT Users
Hi,

The instructions here https://www.gwtproject.org/doc/latest/tutorial/appengine.html are no longer valid, as the Google Plugin for Eclipse is now dead (Google no longer supports Java 1.8, and the Google Plugin for Eclipse doesn't support any Eclipse versions that support anything after Java 1.8).  Ref:  https://github.com/GoogleCloudPlatform/google-cloud-eclipse/issues/3710

The new approach with GAE is to use Maven or Gradle with Google Cloud Tools.

I've been struggling to work out how this is supposed to happen.  It looks like we now have to provide our own Web Server for GAE, but can we use the Jetty server that GWT uses for development?  I assume the deploy build would not include the Jetty web server?

If anyone has deployed a GWT app to GAE with Maven and the new Google Cloud Tools, it would be great if you could give high level instructions on how it's all supposed to fit together.

An example Maven POM file with both the Google Cloud Tools, and GWT would be even better.  🙂

Thanks!

tim_mac...@yahoo.co.uk

unread,
Dec 19, 2023, 9:51:55 PM12/19/23
to GWT Users
For some years I've been deploying GWT 2.8.2 to GAE with Maven & Google Cloud Tools.
I now find GAE is not supporting Java 8 after January, so currently upgrading (rather slowly).
There are 4 long POM files,  probably better to mail them then post a distilled version here ?

Craig Mitchell

unread,
Dec 19, 2023, 11:46:03 PM12/19/23
to GWT Users
No worries not posting the POMs Tim.

The bit I'm struggling with, the old Java 8 version had its own GAE server.  So I would run that, and a GWT Code Server.  Easy!

btw: I'm talking about GAE Standard.  GAE Flexible you can do whatever you want, but that's more work and more expensive.

Now with the upgrade to Java17 on GAE, there isn't a web server included anymore.  It's up to you to supply one.  I would assume when you deploy it, it doesn't actually use your server, but what setup is GAE expecting for the deploy?

I see there is a SpringBoot GAE example, so it might be easier to use that, and get GWT to work with SpringBoot.  Not sure.  Very interested to hear what you're doing.

Thanks!

tim_mac...@yahoo.co.uk

unread,
Dec 20, 2023, 12:06:46 PM12/20/23
to GWT Users
I havent tried raising the Java level yet, its still  JavaSE-1.8.
Got as far as using latest versions:
JDK 21
gcloud CLI app & cloudSdkVersion  457.0.0
appengine-maven-plugin 2.5.0

To get it to run, so far:
1 I had to remove all DOCTYPE declarations in xml files in the server project (new restrictions on DTD)
2 appengine-maven-plugin 2.5.0 requires:
                <configuration>
                    <jvmFlags>
                        <item>--add-opens</item>
                <item>java.base/java.util=ALL-UNNAMED</item>
This stops 500 Server Error which I've not seen before:
GCLOUD: java.lang.reflect.InaccessibleObjectException:
Unable to make field accessible: module java.base does not "opens java.util" to unnamed module @2c95ac9e

So Craig, you say with Java17 on GAE, there isn't a web server included anymore.
So this has to be defined somewhere in  appengine-maven-plugin ?
The minimum level to avoid being shut down on GAE standard is >8
& 11 is the max for GWT, so that would seem do for now, why Java 17  ?

Craig Mitchell

unread,
Dec 21, 2023, 6:27:01 AM12/21/23
to GWT Users
Hi Tim,

I thought GWT 2.10.0 supported Java17.  From the release notes:   https://www.gwtproject.org/release-notes.html#Release_Notes_2_10_0
Tested support for running on Java 17, dropped remaining support for running on Java 7.

I'm also using appengine-maven-plugin 2.5.0.
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>2.5.0</version>
<configuration>
<projectId>headtoheaddrifting</projectId>
<version>GCLOUD_CONFIG</version>
</configuration>
</plugin>

Along with GWT plugin:
<plugin>
<groupId>net.ltgt.gwt.maven</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.1.0</version>
<extensions>true</extensions>
<configuration>
<moduleName>team.drift.DriftTeam</moduleName>
<moduleShortName>dt</moduleShortName>
<packaging>gwt-lib</packaging>
<launcherDir>${project.build.directory}/gwt/launcherDir</launcherDir>
<warDir>${project.build.directory}/drift-team-1.0-SNAPSHOT</warDir>
<startupUrls>
<startupUrl>index.html</startupUrl>
</startupUrls>
</configuration>
</plugin>

Running: "mvn gwt:devmode" I can get it to start the Jetty server and GWT code server.  It finds my project, but currently, when opening the browser it says:
HTTP ERROR 503 Service Unavailable
URI: /index.html
STATUS: 503
MESSAGE: Service Unavailable
SERVLET: -

I put my web assets in  src/main/webapp  and I don't think it's seeing them.  Plus I don't think it's seeing my web.xml that's in  src/main/webapp/WEB-INF/web.xml

Maybe they need to be copied to the target directory or somewhere, or the GWT plugin pointed to where they are somehow.  Not sure.  Any help is greatly appreaciated.

Craig Mitchell

unread,
Dec 21, 2023, 6:36:51 AM12/21/23
to GWT Users
Forgot to mention.  My target is Java 17, but my source is Java 1.8.

So:
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>

And:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.11.0</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
</plugins>
</pluginManagement>

I've attached my current POM (which isn't working, so don't copy it 🙂), but if you can see my mistake, please let me know.

Thanks again!
pom.xml

tim_mac...@yahoo.co.uk

unread,
Dec 21, 2023, 12:41:07 PM12/21/23
to GWT Users
These are my current poms, based on the tbroyer archetype.
Probably best to look at the latter first if youre not familiar with it.

The launch is configured in the server pom:

    <profile>
      <id>env-dev-gae1</id>
      <activation>
        <property>  
          <name>env</name>
          <value>haslistener</value>
...
      <build>                    
        <pluginManagement>
          ...

              <groupId>com.google.cloud.tools</groupId>
              <artifactId>appengine-maven-plugin</artifactId>

A version of Jetty is attached by the appengine-maven-plugin config here (afaik)
The eclipse launch goal is: appengine:run -Denv=haslistener

Re GWT 2.10 : it can use JRE 17 but can only compile Java 11 source, iirc.

Poms are a bit messy but should help if you want to take this approach
pom.xml
pom.xml
pom.xml
pom.xml

Craig Mitchell

unread,
Dec 22, 2023, 11:28:36 PM12/22/23
to GWT Users
Thanks Tim!  Looking at your POM files, I see I missed adding:

<outputDirectory>${project.build.directory}/${project.artifactId}-${project.version}/WEB-INF/classes</outputDirectory>

I also needed to:
  • Convert all my servlets to @WebServlet (as the GWT Jetty server didn't pick up my web.xml like the GAE server used to).
  • Give the GWT plugin the JVM arg "--add-opens java.base/java.lang=ALL-UNNAMED" for execeptions to be returned to the client.
Strangely, Maven isn't copying my src/main/webapp files to the target folder, so I'm doing that manually with the maven-resources-plugin.

So now GWT starts, dev compiles (including source maps), and runs beautifully, including RPC calls.  Java17 runtime with a Java11 source level.  Happy days!  New POM attached.

I've switched from using Eclipse to IntelliJ (because I no longer will be using any of the Eclipse plugins, and wanted a fresh start).  However, debugging my server never hits the breakpoints.

Do you use IntelliJ, do we need any special params to enable debug?

debug.png

I'm yet to get Google App Engine to work.  When I try to access any of the GAE calls, I just get "No API environment is registered for this thread.".  I think I need to setup the enviroment somehow now I no longer have a GAE server.

Cheers!
pom.xml

Craig Mitchell

unread,
Dec 23, 2023, 2:35:42 AM12/23/23
to GWT Users
Managed to get server debugging working by adding:

<jvmArg>-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005</jvmArg>

to the gwt-maven-plugin.

And then creating a Remote JVM Debug launcher in IntelliJ (on port 5005), that I run after running gwt:devmode.

I'm surprised IntelliJ can't just automatically attach to the running server.  Is this what everyone does that uses gwt:devmode?

tim_mac...@yahoo.co.uk

unread,
Dec 23, 2023, 1:28:35 PM12/23/23
to GWT Users
Afaik gwt:devmode is launching  a GWT Jetty, rather than the GAE Jetty.
The latter requires appengine:run
with a launch profile env property & name
appengine:run -Denv=haslistener

As you say: for IDE debugging: we need a Remote Java Application & jvmFlags, discussed at length here:
https://stackoverflow.com/questions/138511/what-are-java-command-line-options-to-set-to-allow-jvm-to-be-remotely-debugged
someone says:
For Java 5 and above, run it with:
-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=1044
rather than
Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=n
I havent tried this yet.

With this setup the dev GAE server uses the cloud datastore (& blobstore I think).
To fix, in the gloud CLI app run:
gcloud components install cloud-datastore-emulator
If you didnt install beta commands, it will prompt for that.
cloud-datastore-emulator 2.3.1
before launch of GAE server run:
gcloud beta emulators datastore start --project='prjname' --host-port=localhost:8081 --data-dir=C:\Users\tim_m\eclipse-workspace\Snptn\Snptn-server\src\main\webapp

Set environment variable in the eclipse launch to attach this DATASTORE_EMULATOR environment
Last time I looked: the local datastore viewer cant show objectify entities, only blobstore files.

Re  copying src/main/webapp files to the target folder: afaik that is done by
maven-jar-plugin jar goal (jar:jar) which is invoked by calling package (phase)
 
Btw I often read that the tbroyer multi-project pattern is better because it keeps server & client dependencies separated, but its a more complex pattern.
Re the poms I attached here: 1 problem is inconsistencies in:
    <!-- To define the plugin version in your parent POM -->
    <pluginManagement>

    <!-- To use the plugin goals in your POM or parent POM -->
    <plugins>

Craig Mitchell

unread,
Dec 23, 2023, 6:26:49 PM12/23/23
to GWT Users
Thanks again Tim!

> Afaik gwt:devmode is launching  a GWT Jetty, rather than the GAE Jetty.
> The latter requires appengine:run

This is no longer an option.  appengine:run no longer works with Java17.  You have to provide your own web server.  See https://cloud.google.com/appengine/migration-center/standard/migrate-to-second-gen/java-differences#key-differences

I'm still trying to figure out if I can just use the bundled GWT Jetty server, or do I include my own Jetty / Embedded Tomcat / ... server.

> As you say: for IDE debugging: we need a Remote Java Application & jvmFlags, discussed at length here:

Thank you!  Those options work much better.  In IntelliJ, I've now setup a "compound" launcher that launches both the gwt:devmode and the remote JVM debug at the same time.

> With this setup the dev GAE server uses the cloud datastore (& blobstore I think).
> To fix, in the gloud CLI app run:
> gcloud components install cloud-datastore-emulator
> before launch of GAE server run:
> gcloud beta emulators datastore start --project='prjname' --host-port=localhost:8081 --data-dir=C:\Users\tim_m\eclipse-workspace\Snptn\Snptn-server\src\main\webapp

I tried this, and the emulator starts no problem.  However, I still get the "No API environment is registered for this thread.".

I might switch to use SpringBoot, then it'll use its Jetty server, and I'll switch away from the GWT Jetty server (and just use the GWT code server), and then it'll hopefully magically work.

> Re  copying src/main/webapp files to the target folder: afaik that is done by
> maven-jar-plugin jar goal (jar:jar) which is invoked by calling package (phase)

I figured it out.  It's because GAE wants an executable JAR ( https://cloud.google.com/appengine/docs/standard/testing-and-deploying-your-app?tab=java#other_deployment_options ), however, the src/main/webapp files are only copied when creating a war with the maven-war-plugin.

I'll need to figure out how to include the static files with an executable JAR, or if I switch to SpringBoot, I think SpringBoot handles this for me.

> Btw I often read that the tbroyer multi-project pattern is better because it keeps server & client dependencies separated, but its a more complex pattern.

I might end up changing to this structure.  I wanted to keep it as simple as possible, as my project isn't complicated, but might still be a better option.

Cheers!

tim_mac...@yahoo.co.uk

unread,
Dec 24, 2023, 11:48:23 AM12/24/23
to GWT Users
Looks like Cloud CLI provides a dev server if  using the legacy bundled services (App Engine API JAR)?
If you are using the legacy bundled services, the second-generation Java runtimes provide the Jetty web-serving framework.
https://cloud.google.com/appengine/migration-center/standard/migrate-to-second-gen/java-differences#framework_flexibility
The Google Cloud CLI for Java includes a local development server for testing your application on your computer. The local development server emulates the App Engine Java runtime environment and all of its services, including Datastore.
What do you think ?

Re. static files: in my setup appengine:deploy at base directory server project deploys  SNAPSHOT.war. 
Static files in \src\main\webapp end up in its root directory. 
says in the case of a JAR-file, src/main/webapp has no special meaning and goes on about jar directories that work with Springboot.


Message has been deleted

Craig Mitchell

unread,
Dec 25, 2023, 7:21:05 PM12/25/23
to GWT Users
Odd, my message was deleted.  Maybe it was too boring.  :-D

The highlights:
  • I'm not sure if you get a Jetty server bundled or not if you use the legacy bundled services.  The documentation is a little ambiguous to me.
  • You do get a stand alone server "dev server" that you can deploy a war to.  Great for final testing, but it's unclear if you'll be able to debug on it.
  • Your static files worked because the legacy version allows a war file, and you have the maven-war-plugin in your POM.
  • If I switch to SpringBoot, I'll move my static files to either a /public or /static directory.
Personally, I'm going to skip the legacy bundled services, and just use the second-generation Java runtime with my own web server.

Cheers!

tim_mac...@yahoo.co.uk

unread,
Dec 26, 2023, 12:15:34 PM12/26/23
to GWT Users
Maybe this thread is gettig a bit off-topic for gwt ? maybe more suitable for Stackoverflow

Craig Mitchell

unread,
Feb 20, 2024, 7:20:03 PMFeb 20
to GWT Users
Now I have it all working.  This is what I found:

Google App Engine Standard no longer gives you a web server, so you need to provide your own.
If you want to run on the cheap F1 Google App Engine instances, Tomcat is too heavy, and you'll run out of memory.  You can easily switch Spring Boot to use Undertow, which is a lightweight web server, and runs great on the F1 instances.

Cheers.

Thomas Broyer

unread,
Feb 21, 2024, 6:17:07 AMFeb 21
to GWT Users
Fwiw, I haven't used WARs for years (and by years I mean more than a decade), but the archetype is only there to help you get started with cleanly separated client/shared/server modules, and I don't want to impose my own opinionated way of building apps to others (or possibly start bikeshedding wars (sic!)), so I chose a WAR target and tried to find a plugin to make it easy to run the app, so Jetty it was (there used to be a Tomcat plugin that worked really well, better than Jetty even, but it's been un maintained for years so…)
Of course if you want something that scaffolds everything for you, then go with Spring (I personally can't stand this ecosystem but YMMV)

(also fwiw, I haven't really used Maven for years either, and never used archetypes other than for quickly building bug repros/MCVEs or as examples/inspiration for projects, that I always start from scratch)

Tim Macpherson

unread,
Feb 21, 2024, 9:11:54 AMFeb 21
to google-we...@googlegroups.com
I've been trying this app engine sample for Java 11+ which uses a JAR packaged artifact that is installed locally:
it provides a Main class to instantiate an HTTP server to run an embedded web application WAR file.
It has explicit jetty 11 dependencies.

The WAR project is
The WAR is run in a local server with:
mvn exec:java -Dexec.args="../helloworld-servlet/target/helloworld.war"

The problem I have is when I include GWT in the WAR project this draws in Jetty 9 & other dependencies
which get copied to the cloud-deployment dependencies directory. I tried to prevent this with exclusions & 
explicit dependencies  in the WAR project but the final dependencies are always at least sightly affected & cloud-deploy
fails with some kind of 503.

Currently I'm trying to use tomcat-embed-core but now the problem is locally installed maven dependencies 
seem to be inaccessible at runtime. Is anyone aware of any samples that can help ? 
Thanks



--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/google-web-toolkit/bf837675-5a64-4cc5-8b1d-f4884be1a773n%40googlegroups.com
.

Thomas Broyer

unread,
Feb 21, 2024, 12:42:37 PMFeb 21
to GWT Users
On Wednesday, February 21, 2024 at 3:11:54 PM UTC+1 tim_mac...@yahoo.co.uk wrote:
I've been trying this app engine sample for Java 11+ which uses a JAR packaged artifact that is installed locally:
it provides a Main class to instantiate an HTTP server to run an embedded web application WAR file.
It has explicit jetty 11 dependencies.

The WAR project is
The WAR is run in a local server with:
mvn exec:java -Dexec.args="../helloworld-servlet/target/helloworld.war"

The problem I have is when I include GWT in the WAR project this draws in Jetty 9 & other dependencies
which get copied to the cloud-deployment dependencies directory.

This means you WAR have dependencies on gwt-user and/or gwt-dev, that you never want to deploy to a server. The WAR should have a dependency on gwt-servlet only (or requestfactory-server).

…and this is exactly what https://github.com/tbroyer/gwt-maven-archetypes were meant to solve.

Tim Macpherson

unread,
Feb 21, 2024, 1:30:51 PMFeb 21
to google-we...@googlegroups.com
I tried starting with the tbroyer archetype & to the server project I added the app engine stuff from the Google sample to build the appengine-staging dependencies directory.
Maybe all that should be in a separate project ?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-tool...@googlegroups.com.
To view this discussion on the web visit

Craig Mitchell

unread,
Feb 22, 2024, 6:05:22 PMFeb 22
to GWT Users
I know it's outside of its scope, but it would be great if https://github.com/tbroyer/gwt-maven-archetypes had an example of "If you want to create an executable jar with Jetty, this is how you could do it".  🙂

Ralph Fiergolla

unread,
Feb 23, 2024, 1:45:13 AMFeb 23
to google-we...@googlegroups.com
Don’t want to build up pressure, but yeah that would come in very handy 😎

Tim Macpherson

unread,
Feb 23, 2024, 12:29:28 PMFeb 23
to google-we...@googlegroups.com
Could try moving the gwt dependency out of the root pom, keeping it only for the client, just gwt-servlet for sever and shared ( unless anyone knows better). That will clean up the server dependencies but may cause other problems 

Craig Mitchell

unread,
Feb 23, 2024, 6:45:43 PMFeb 23
to GWT Users
Could try moving the gwt dependency out of the root pom, keeping it only for the client, just gwt-servlet for sever and shared ( unless anyone knows better). That will clean up the server dependencies but may cause other problems 

I believe that's how it works now.  The root pom just has the dependencyManagement ( https://github.com/tbroyer/gwt-maven-archetypes/blob/main/modular-webapp/src/test/resources/projects/basic-webapp/reference/pom.xml#L17 ).  It doesn't actaully include it as a dependency.

The server and shared module poms include the gwt-servlet lib, and the client pom includes the gwt-user + gwt-dev libs.

Thomas Broyer

unread,
Feb 24, 2024, 7:14:32 AMFeb 24
to GWT Users
I could easily write a Main class that runs an embedded Jetty server (https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-server-http-handler-use-servlet-context) with the configured GWT-RPC servlet and serving static resources from multiple dirs (https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-server-http-handler-use-resource), but then there would still be a whole lot of questions either unanswered or with an necessarily opinionated answer:
  • how to set "dev mode" for the Main class? (to add the codeserver's launcherDir to the resource bases; I would personally use a system property with the launcherDir's path and react to its presence/absence)
  • how to package/deploy the static resources? as resources in the JAR? (that's what I'd do if I'd wanted my deliverable to be a single JAR) as a directory alongside the JAR? (that's what I'd do if my deliverable were a native deb/rpm/whatever package or a Docker image)
  • that Main class would likely not be production-ready (should it use the QoSHandler? GzipHandler? how about the CrossOriginHandler? the ForwardedRequestCustomizer?)
  • you'd probably want to refactor the Main class anyway to add command-line arguments and/or configuration files, a logging framework, possibly dependency-injection, etc.
My question is: what do you expect from such an archetype?

The initial goal was to show how to cleanly/clearly separate client/shared/server classpaths, which involves some configuration for how to run the server so it serves the codeserver's launcherDir. As soon as you go "custom" on the server, you have to handle that specific "dev mode" configuration, but then it's custom to your custom code, and necessarily becomes somewhat opinionated. This means that the archetype can't really "show you how to do things" without being opinionated, and I don't want to go that road (I specifically don't want to maintain such an opinionated thing). Feel free to create opinionated archetypes though, and I'll happily review them and help you set them up (this will bring my own opinions into the mix though)


Tim Macpherson

unread,
Feb 24, 2024, 2:11:38 PMFeb 24
to google-we...@googlegroups.com
The gwt artifact is indeed in dependency management, but when the jetty-main jar for jetty 11 is a dependency of server module it draws in jetty 9 dependencies and and also gwt-servlet leading to a no javax-servlet error. Remove gwt from the root fixes it.  Maybe this will cause problems beyond this sample.
On Sat, Feb 24, 2024 at 12:14, Thomas Broyer
I could easily write a Main class that runs an embedded Jetty server jagwtvax(https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-server-http-handler-use-servlet-context) with the configured GWT-RPC servlet and serving static resources from multiple dirs (https://eclipse.dev/jetty/documentation/jetty-12/programming-guide/index.html#pg-server-http-handler-use-resource), but then there would still be a whole lot of questions either unanswered or with an necessarily opinionated answer:

Thomas Broyer

unread,
Feb 24, 2024, 5:40:35 PMFeb 24
to GWT Users
In retrospect, I think the GWT BOM (to avoid managing non-GWT dependencies where there's no need to) possibly either should only be used in the client module, or should really only list GWT artifacts. That being said, if you use the Jetty BOM in the server module (and you should), it should override the GWT BOM.

Craig Mitchell

unread,
Feb 24, 2024, 7:11:49 PMFeb 24
to GWT Users
My question is: what do you expect from such an archetype?

It would be great to have an example for a minimum viable product.  So how to do a mvn package on an app created with https://github.com/tbroyer/gwt-maven-archetypes to get an executable jar that doesn't need an existing web server.

> I could easily write a Main class that runs an embedded Jetty server with the configured GWT-RPC servlet and serving static resources from multiple dirs.

If that's what we need to get an executable jar, yes please!  🙂

Tim Macpherson

unread,
Feb 25, 2024, 2:10:23 PMFeb 25
to google-we...@googlegroups.com
If nobody is interested in maintaining such, it could be presented as a demonstration valid in 2024. I can post my version of it and others can make revisions or advise.
Reply all
Reply to author
Forward
0 new messages