I have designed an Java application that reads the data from the database and writes in excel file. I have used Apache-POI to create the excel file and Desktop class to auto open that excel file as soon as it is created. When I run the program in my local machine (Windows 7, Eclipse, Apache-tomcat ) the application successfully creates the excel file and opens it automatically.
Then I created a WAR file of the application and deployed it to the remote server (Window server 2012) in Apache-tomcat. But this time when I run application the excel file is created in the desired location but it doesn't open automatically???
My Java method for creating excel file and to auto open it looks like this:
public void excelReport() {
// my Apache-POI code for creating excel file is here which is not included
String excelFileName = costReport.xls
String excelFilePath = D:/projects/workspace/tomcat/webapps/reports/excel/
String fullExcelPath = excelFilePath + excelFileName;
FileOutputStream out = new FileOutputStream(new File(fullExcelPath));
// write operation workbook using file out object
workbook.write(out);
out.flush();
out.close();
// Close workbook
workbook.close();
// Open excel file as soon as excel file is created
try {
if (Desktop.isDesktopSupported()) {
Desktop.getDesktop().open(new File(fullExcelPath)); // Used this class to auto open the excel file as soon as it is created but it doesn't work
}
} catch (Exception e) {
e.printStackTrace();
}
}
Could someone kindly help me to figure out the solution of this problem?