我正在Google App Engine Flex环境上运行一个应用程序(播放框架),该应用程序正试图从Google云端硬盘下载文件。当我尝试下载代码时,出现此错误:
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)
我发现了一些有关正在发生的事情的帖子,但是对Google App Engine Flex and Play Framework没什么帮助:
"No X11 DISPLAY variable" - what does it mean?
Start X server on Google Cloud (Debian) Compute Engine
这是我正在使用的代码:
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();
}
}
来自这篇文章:
How to force download of file from Google Team Drive using Google Drive API libraries in Java
从这篇文章中,我看到我可能需要设置一个变量DISPLAY=0:0
:
如何在Play Framework应用程序中设置此变量,或者可以在Google App Engine Flex实例上进行设置?
感谢您的帮助。
答案 0 :(得分:0)
您可以在App Engine flexible中设置environment variables。因此,根据您的情况,尝试像这样编辑app.yaml
文件:
env_variables:
DISPLAY=0.0