1

I am running an application (Play Framework) on the Google App Engine Flex environment, that is trying to download a file from the Google Drive. When I attempt to download the code, I receive this error:

java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
at java.awt.Desktop.getDesktop(Desktop.java:142)

I found a few posts on what is happening but nothing to help me with the Google App Engine Flex and Play Framework:

"No X11 DISPLAY variable" - what does it mean?

Start X server on Google Cloud (Debian) Compute Engine

Here is my code that I am using:

public static void downloadFile(String fileID) {
    // Set the drive service...
    Drive service = null;
    try {
        service = getDriveService();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        Desktop desktop = java.awt.Desktop.getDesktop();
        // place your webContentLink in the oURL variable
        URI oURL = new URI("https://drive.google.com/a/google.com/uc?id=" + fileID + "&export=download");
        desktop.browse(oURL);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

which came from this post:

How to force download of file from Google Team Drive using Google Drive API libraries in Java

I see that, from this post, that I may need to set a variable DISPLAY=0:0:

https://superuser.com/questions/1223939/no-x11-display-variable-was-set-but-this-program-performed-an-operation-which-r

How do I set this variable inside the Play Framework application or can I set on the Google App Engine Flex instance?

I appreciate the help.

Dan
  • 940
  • 2
  • 14
  • 42

1 Answers1

0

You can set environment variables in App Engine flexible. So, in your case, try to edit your app.yaml file like this:

env_variables:
    DISPLAY=0.0
Mangu
  • 3,160
  • 2
  • 25
  • 42