Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upgrade App Engine servlet-api-2.5 to servlet-api-3.1?

With the recent announcement of support for Servlet 3.1, I cannot figure out how to modify the App Engine Standard environment to use 3.1 instead of 2.5 in a non-Maven build.

It seems there is no way to upgrade to 3.1?

https://cloudplatform.googleblog.com/2017/06/Google-App-Engine-standard-now-supports-Java-8.html

like image 755
Chris Fremgen Avatar asked Jun 29 '17 20:06

Chris Fremgen


2 Answers

Here is a full example given here: https://github.com/GoogleCloudPlatform/getting-started-java/tree/master/appengine-standard-java8/helloworld

Running procedure is also attached.

For Gradle Users:

For non-maven users, you can use gradle.

In gradle build file, line number 39 denotes: https://github.com/GoogleCloudPlatform/getting-started-java/blob/master/appengine-standard-java8/helloworld/build.gradle#L39

providedCompile 'javax.servlet:javax.servlet-api:3.1.0'

Running locally:

gradle appengineRun

If you do not have gradle installed, you can run using ./gradlew appengineRun.

To use visit: http://localhost:8080/

For Maven Users

In pom.xml, line number 62 to 70 denotes that it is using servlet version 3.1.0: https://github.com/GoogleCloudPlatform/getting-started-java/blob/master/appengine-standard-java8/helloworld/pom.xml#L66

<!-- [START servlet] -->
<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.1.0</version>
  <type>jar</type>
  <scope>provided</scope>
</dependency>
<!-- [END servlet] -->

Hope it will clarify you.

like image 174
SkyWalker Avatar answered Oct 20 '22 08:10

SkyWalker


These are the steps that should work no matter what technique is used, as long as it produces a valid war that includes javax.servlet-api:3.1.0:

1) As documented, make sure you've added <runtime>java8</runtime> to your appengine-web.xml file

2) uncompress the war into its own separate directory

3) deploy using the appcfg.sh script found on App Engine SDK for Java bin directory. It will look something like:

/<some-path>/appengine-java-sdk-1.9.54/bin/appcfg.sh update /<some-path>/exploded-war/

Note: To verify ServletContext's version from within a servlet I've used:

ServletContext sc = req.getSession().getServletContext();
resp.getWriter().println("Servlet version = " + sc.getMajorVersion() + "." + sc.getMinorVersion());
like image 42
Mar Cial R Avatar answered Oct 20 '22 09:10

Mar Cial R