我正在 Google App Engine Flex 环境中运行一个应用程序(Play 框架),该应用程序正在尝试从 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 和 Play 框架:
"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 实例上设置吗?
非常感谢您的帮助。
最佳答案
您可以设置environment variables在 App Engine 中灵活。因此,对于您的情况,请尝试像这样编辑您的 app.yaml
文件:
env_variables:
DISPLAY=0.0
关于java - Google App Engine Flex 在运行 Play Framework 应用程序时出现 No X11 DISPLAY variable was set 错误;我在哪里设置这个变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51330250/