Problem
Weird thing: My Eclipse (and also the one of my colleague) does not know "Desktop".What I mean: I type "Desk" in my Java code and try to autocomplete but Eclipse does not suggest "Desktop". So it seems, like there is no "Desktop"-Class.
But the java.awt.Desktop class is still available, it just seems to be "secret"/hidden.
**Any explanation, why Eclipse hides "Desktop" from us?**
I use Java 8 in my project. Eclipse itself starts with Java 11 or 13. (how can I check?)
This code is an example and working, so the java.awt.Desktop itself is there, only "hidden" in Eclipse:
package mystuff;
import java.awt.Desktop;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
public class PDFStuff {
public static final String dummyPDF = "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf";
public static void main(String[] args) throws Exception {
String FILE_URL = dummyPDF;
String FILE_NAME = "dummy.pdf";
InputStream in = new URL(FILE_URL).openStream();
Files.copy(in, Paths.get(FILE_NAME), StandardCopyOption.REPLACE_EXISTING);
Desktop.getDesktop().open(Paths.get(FILE_NAME).toFile());
}
}
Solution
There was a bug in eclipse and after an update it is working well again! Thanks @greg-449!
PS: I had another bug, so first I could not update Eclipse.
Problem was, that Eclipse could not remove eclipse.exe during the update process.
This is how I fixed it:
- Run eclipse
- Rename eclipse.exe to eclipse.exe.backup
- Run updates
- Updates executed successfully
- Remove eclipse.exe.backup