2

I have a java web-application which uses the jacob library (running both in 32bit and in 64bit) to create/open word files. It correctly runs on my machine (32bit), it means that the word application is launched and the word file is opened. The problem arise when the java project is loaded on the server machine (64bit): the word application will be launched (I see "WINWORD.EXE * 32" on Task Manager window), but the file is not opened.

I don't understand what am I missing.

May you help me? Thanks in advance.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
mrod
  • 23
  • 3
  • Errors, warnings, exceptions, code sample? I can successfully use the jacob library with both a 32bit and 64bit VM communicating with a 32bit COM object (Word 2010 32bit). – Anya Shenanigans Apr 13 '12 at 14:08
  • No errors, no warnings, nothing. – mrod Apr 13 '12 at 14:32
  • No errors, no warnings, nothing. The only thing I do is: ActiveXComponent word = new ActiveXComponent("Word.Application"); word.setProperty("Visible", new Variant(true)); inside a jsp file. I also include com.jacob.com and com.jacob.activeX at the top of the page. At this step I only want to se the word process opening, but I see anything. – mrod Apr 13 '12 at 14:39
  • Try invoking the LibraryLoader directly - com.jacob.com.LibraryLoader.loadJacobLibrary(); and wrap the loading in a try-catch block. I strongly suspect that the .dll is not being loaded (missing/not on system.library.path/security violation) – Anya Shenanigans Apr 13 '12 at 15:48

1 Answers1

2

I'd strongly suspect one of the following things is happening:

  1. Security Violation
  2. Unsatisfied Link Error
  3. Word is not installed on the server
  4. Some other classloader error (edit)

I tried with a simple jsp, and invoked the LibraryLoader directly within a try-catch block:

 try {
   LibraryLoader.loadJacobLibrary();
   ActiveXComponent oWord = new ActiveXComponent("Word.Application");
   oWord.setProperty("Visible", new Variant(true));
 } catch (Throwable th) {
   th.printStackTrace(new java.io.PrintWriter(out));
 }

and hit on a failure to initialize the JacobObject class - caused because of security violation from the static debug initializer: "true".equalsIgnoreCase(System.getProperty("com.jacob.debug"));. Once I replaced that with a simple assignment to true, and replaced it in the jacob.jar, I ended up with a: java.lang.UnsatisfiedLinkError: no jacob-1.16-x64 in java.library.path

It's at this point things get hairy. You will probably have to replace the LibraryLoader code that replaced the method loadJacobLibrary with something like:

public static void loadJacobLibrary() {
  System.load("C:/<path to .dll as known on the server>/" + getPreferredDLLName() + ".dll");
}

Which then invoked the Word.Application.

edit For the some other classloader error, the underlying issue is that you can only load one instance of a .dll within the server - This refers to using tomcat, but the issue is similar with all other servlet containers - you need to load the .dll only once, and in order to ensure that the code is available across all the servlets, it needs to be loaded into a classloader that doesn't get disturbed by reloading the web application. If that happens then you will become unable to make use of the .dll until the server application is reloaded.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • I tried to create an executable file which creates an empty doc file (always using jacob library). It runs correctly both on my machine (32bit) and on the server (64bit). So the problem is strictly related to the opening of the word file, that is I can't see the doc file, while the process has been started. – mrod Apr 18 '12 at 07:38
  • By 'see', do you mean see on the UI or see on the file system? You still have not stated what the security context of the servlet container (e.g windows service, launched from a desktop session), and does the file that you intend to create get placed in a known location that has permission to be written to by the servlet container – Anya Shenanigans Apr 18 '12 at 07:57