You can use any Java compatible libraries with the Java runtime on the
App Engine flexible environment.

These instructions use Apache Maven to build, run, and deploy a sample app using
a [supported](https://docs.cloud.google.com/appengine/docs/flexible/lifecycle/support-schedule#java) Java
runtime. For more information about using supported Java versions, see the
[Java runtime](https://docs.cloud.google.com/appengine/docs/flexible/java/runtime).
For details about installing Maven, see [Using Apache Maven and the App Engine plugin](https://docs.cloud.google.com/appengine/docs/flexible/java/using-maven).

<br />

## Declare and manage dependencies

To manage dependencies using Maven, you need to specify the dependencies in
the `<dependencies>` section inside the
[`pom.xml`](http://maven.apache.org/guides/introduction/introduction-to-the-pom.html)
file of your project.

To manage your project's dependency on Maven itself, you can use the
[Maven Wrapper](https://maven.apache.org/wrapper/). If you do not use the
Maven Wrapper, App Engine defaults to using a recent version of Maven
when running [`gcloud app deploy`](https://docs.cloud.google.com/sdk/gcloud/reference/app/deploy).

## Specify the Java servlet library

Eclipse Jetty and Tomcat apps require the Java servlet library. Specify it in
your `pom.xml` file's `<dependencies>` entry:


    <dependency>
      <groupId>com.example.appengine</groupId>
      <artifactId>simple-jetty-main</artifactId>
      <version>1</version>
      <scope>provided</scope>
    </dependency>

Note that frameworks such as [SparkJava](http://sparkjava.com/) or [Spring Boot](http://projects.spring.io/spring-boot/) won't require the servlet library.

<br />

## Use the Cloud Client Libraries

[Cloud Client Libraries for Java](https://github.com/googleapis/google-cloud-java)
provide idiomatic access to Google Cloud services. To use a library, declare
it as a dependency.

Typically, you only declare dependencies on the specific libraries that your app
needs. For example, to use the Cloud Storage library:


    <!--  Using libraries-bom to manage versions.
    See https://github.com/GoogleCloudPlatform/cloud-opensource-java/wiki/The-Google-Cloud-Platform-Libraries-BOM -->
    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>com.google.cloud</groupId>
          <artifactId>libraries-bom</artifactId>
          <version>26.28.0</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>

    <dependencies>
      <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-storage</artifactId>
      </dependency>
    </dependencies>

You can configure the Cloud Client Libraries for Java to
[handle authentication automatically](https://docs.cloud.google.com/docs/authentication/client-libraries).