Not easy to summarize the problem in a single sentence ...
I have an web app running on tomcat 7, with Java 6. The app accesses Excel sheets using JACOB, which uses JNI and COM, starting an separate Excel process. To ensure, the Excel sheet is mutable, my Java process creates a copy of the original XLS using File.createTempFile() and passes the temp file to the Excel process.
OS is Windows Server 2008. Excel version is from Office 2010.
My Problem: Everything works fine as long as Tomcat is started interactively from command line or frm the IDE. If I start Tomcat as service (with default user SYSTEM), Excel fails to open the temp file saying:
com.jacob.com.ComFailException: Invoke of: Open
Source: Microsoft Excel
Description: Microsoft Excel kann auf die Datei 'C:\Program Files\apache-tomcat\temp\Entwickl-Auftr-Bez-n-Maß 54-131 215-2 Optimierung 210-0 210-3.xlsx6119727457676255726.clone' nicht zugreifen. Dies kann mehrere Gründe haben:
• Der Name des Dokuments oder der Pfad ist nicht vorhanden.
• Das Dokument wird von einem anderen Programm verwendet.
• Der Name der Arbeitsmappe, die gespeichert werden soll, ist identisch zu dem Namen eines anderen Dokuments, welches schreibgeschützt ist.
com.jacob.com.Dispatch.invokev(Native Method)
com.jacob.com.Dispatch.invokev(Unknown Source)
com.jacob.com.Dispatch.callN(Unknown Source)
com.jacob.com.Dispatch.call(Unknown Source)
de.insites.ms.com.xls.Workbook.<init>(Unknown Source)
de.insites.ms.com.xls.Excel.openWorkbook(Unknown Source)
de.harti.harticalc.excel.MahanoExcel.<init>(Unknown Source)
de.harti.harticalc.excel.MahanoExcel.create(Unknown Source)
de.harti.harticalc.excel.ExcelProcessor.getExcel(Unknown Source)
de.harti.harticalc.excel.ExcelProcessor.calculatePosition(Unknown Source)
de.harti.mahano.service.PositionServlet.doGet(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
de.harti.mahano.service.AbstractMahanoWsServlet.service(Unknown Source)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
de.harti.mahano.service.CharsetFilter.doFilter(Unknown Source)
The german message means that Excel can't access the file because the file does not exist, is locked by another process or is somehow write locked.
I verified the file exists and it's a readable Excel document (I can open it using Excel interactively).
My guess is, that Windows denies the access of the EXCEL sub process to my file, because it's created by the java process which it doesn't trust.
How can I give Excel access to the file when Tomcat is running as windows service?
EDIT: English version of the Exception message
ERROR - Invoke of: Open
Source: Microsoft Office Excel
Description: Microsoft Office Excel cannot access the file 'c:\marchena\marchena10\work\marchena\batch_58288\input\content_1.xlsx'. There are several possible reasons:
? The file name or path does not exist.
? The file is being used by another program.
? The workbook you are trying to save has the same name as a currently open workbook.
SOLUTION Found the solution here link. I had to create the folder
C:\Windows\SysWOW64\config\systemprofile\Desktop
manualy. Seems on Windows Server 2008, Excel needs this folder when running as SYSTEM but does not create if missing.
Thanks for your hints.