Open MS Word docx document does not open on Tomcat 9
已回答
Hi
The following code opens a Word docx file. It runs perfectly inside my IntelliJ IDE (IntelliJ IDEA 2022.2.3 (Ultimate Ed.)) where I run '.SmartTomcat' version 9.
However when I package the application to a war file (using Maven) and deploy it to my local Tomcat 9 service it does not open the file and there are no visible errors in the logfiles.
What could be the reason for this behaviour and how could I tackle this problem? Any ideas or hints are welcome?
Kind regards
Riccardo
public class TestOpenWordDoc {
public static void main(String[] args){
try{
if(Desktop.isDesktopSupported()) {
System.out.println("Desktop supported");
File docxFile = new File("C:\\test_data\\certificate_149.docx");
Desktop.getDesktop().open(docxFile);
} else {
System.out.println("Desktop not supported");
}
}catch (Exception e){
System.out.println("error opening worddoc " + e);
}
}
}
请先登录再写评论。
It looks like a Windows service cannot interact with the desktop i.e. open local GUI applications.
Therefore you can try running Tomcat from command line instead, rather than 'as a service'. Or you can try implementing another component of your application that could communicate with the webapp and open needed desktop applications. Check this SO post used as a source.
Hi Ivan,
When I start Tomcat 9 from the command line, and not as a Windows Service, it works perfectly. Thanks for your help.
Kind regards
Riccardo