UsingJacob.html 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. <HTML>
  2. <BODY>
  3. Jacob is a Java library that lets Java applications communicate with Microsoft Windows DLLs or COM libraries. It does this
  4. through the use of a custom DLL that the Jacob Java classes communicate with via JNI. The library and dll isolate the Java
  5. developer from the underlying windows libraries so that the Java developer does not have to write custom JNI code.
  6. <p></p>
  7. Jacob is not used for creating ActiveX plugins or other modules that live inside of Microsoft Windows applications.
  8. <hr>
  9. <h2> The Jacob Packages </h2>
  10. The JACOB jar contains two main packages: the
  11. <code>com.jacob.com.*</code>> package and the
  12. <code>com.jacob.activeX</code> package. The
  13. <code>com.jacob.com.*</code> package contains classes map very closely to the com dispatch model with the
  14. <code>com.jacob.com.Dispatch</code> acting as the primary communication class. Dispatch operate as a function library with a set of static methods that map
  15. very closely to the C++ Dispatch APIs provided to the COM layer.
  16. <p></p>
  17. <code>com.jacob.activex.ActiveXComponent</code> can be used in place of Dispatch to provide a more object like API. The only exception to this guideline is that the
  18. <code>ActiveXComponent</code> class is always used to make the initial connection to the target dll/COM component.
  19. <hr>
  20. <H2> Considerations when doing server side automation of office </h2>
  21. Most office and many windows client type applications are not written to be used in high volume or multi-threaded server
  22. environment. There is a
  23. <a href="http://support.microsoft.com/kb/257757/">
  24. support note </a>
  25. on the Microsoft web site that discusses some of the issues.
  26. <p></p>
  27. <hr>
  28. <H2> Determining the API of the target application </h2>
  29. Section not yet written.
  30. <hr>
  31. <h2> The Jacob DLL </h2>
  32. Jacob.jar relies on a DLL file that it loads off of the library path or classpath. This means that you must either copy the
  33. appropriate jacob dll into your path or use VM options to add directory holding jacob dll to the path. Prior to 1.14M6,
  34. the jacob DLL name was always "jacob.dll". This made it hard to verify jacob was loading the correct dll when multiple copies
  35. of jacob were installed on a single system. It also was confusing on 64 bit systems where the 32 bit and 64 bit dlls have
  36. the same tames. Starting in 1.14M6, Jacob's library loader selects a dll with the appropriate name based on the jacob release
  37. and platform. The dll naming convention is:
  38. <BR>
  39. <code>jacob&lt;platform&gt;.&lt;version.&gt;.dll</code>
  40. <h3>Classloader issues</h3>
  41. The code is written so that the jacob.dll is only loaded one time per classloader. This works fine in the standard application
  42. but can cause problems if jacob.jar is loaded from more than one class loader. This can happen in the situation where multiple
  43. jacob dependent web applications run in the same container like a web server or JWS runtime. In the case of a web server,
  44. Jacob is normally put in the application specific WEB-INF/lib directory. This is the "right" way to do it and works in most
  45. situations. But, if Jacob is put in the WEB-INF/lib directory of each application's war file for more than one application
  46. then a problem occurs. In this situation, the web server uses a different classloader for each application. This means that
  47. each application will attempt to load the jacob.dll and errors are generated. The only way around this at this time (1.11)
  48. is to put the jacob.jar in the common/lib because that classloader is inherited by all of the applications so the DLLs will
  49. only get loaded once. This problem is described in SF 1645463 and should be fixed in some future release, fix method and
  50. time not yet determined.
  51. <hr>
  52. <h2>Microsoft Visual C++ library dependencies.</h2>
  53. <p>
  54. Jacob 1.15 is build with VC++ 2005 statically linked into the DLL. This removes the need for a separate msvcr80.dll installation.
  55. </p>
  56. <p>
  57. Jacob 1.13 is built with VC++ 2005 that creates a dependency on msvcr80.dll. Windows XP and later seem to already include
  58. the necessary components. NT/2000 and Server/2003 require that you download the Visual C 2005 redistributable package,
  59. vcredist_x86.exe from the Microsoft web site. Microsoft has a download available that supplies the necessary components.
  60. It is distributed as a redistributable package.
  61. </p>
  62. <p>
  63. If you see the following message then you probably don't have the right C++ libraries.
  64. </p>
  65. <pre>
  66. Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\apps\...\jacob.dll: This application has
  67. failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem
  68. </pre>
  69. <A href="http://www.microsoft.com/downloads/details.aspx?familyid=200B2FD9-AE1A-4A14-984D-389C36F85647&displaylang=en">
  70. Visual C redistributable installer SP1</A>
  71. <p></p>
  72. <hr>
  73. <h2>Jacob Command Line Settings</h2>
  74. This library supports several different command line options:
  75. <table border=1>
  76. <tr>
  77. <td colspan=3>
  78. <h3>dll path location and dll name customization</h3>
  79. </td>
  80. </tr>
  81. <tr>
  82. <td>&nbsp;&nbsp;&nbsp;</td>
  83. <td valign="top">
  84. <h4>java.library.path</h4>
  85. </td>
  86. <td>
  87. Standard Java property used to add the location of the jacob dll to the JVM's library path. (Added 1.11)
  88. <p></p>
  89. Example:
  90. <code>-Djava.library.path=d:/jacob/release/x86</code>
  91. </td>
  92. </tr>
  93. <tr>
  94. <td>&nbsp;&nbsp;&nbsp;</td>
  95. <td valign="top">
  96. <h4>jacob.dll.name</h4>
  97. </td>
  98. <td>
  99. Override the standard DLL name with a custom one. This stops jacob from using its 32bit/64bit detection and dll rendezvous
  100. logic. Sometimes used when Jacob is bundled with another application and the application wishes to tie the jacob dll
  101. version number to the application version number. (Added 1.14M7)
  102. <p></p>
  103. Example:
  104. <code>-Djacob.dll.name=MyFunkyDllName.dll</code>
  105. </td>
  106. </tr>
  107. <tr>
  108. <td>&nbsp;&nbsp;&nbsp;</td>
  109. <td valign="top">
  110. <h4>jacob.dll.name.x86 & jacob.dll.name.x64</h4>
  111. </td>
  112. <td>
  113. Override the standard 32 bit DLL name with custom ones. Sometimes used when Jacob is bundled with another application and
  114. the application wishes to tie the jacob dll version number to the application version number. (Added 1.14M7)
  115. <p></p>
  116. Example to override 32 bit dll name:
  117. <code>-Djacob.dll.name.x86=MyFunkyDllName-32bit.dll</code>
  118. </td>
  119. </tr>
  120. <tr>
  121. <td colspan=3>
  122. <h3>Memory Management</h3>
  123. </td>
  124. </tr>
  125. <tr>
  126. <td>&nbsp;&nbsp;&nbsp;</td>
  127. <td valign="top">
  128. <h4>com.jacob.autogc </h4>
  129. </td>
  130. <td>
  131. Determines if automatic garbage collection is enabled. This is the only way to free up objects created in event callbacks.
  132. Automatic garbage collection , based on Java gc rules, garbage collection can be enabled via the
  133. <code>com.java.autogc</code> command line option.
  134. <em>This feature was added in release 1.9 is not fully debugged. </em>
  135. <p></p>
  136. There are real reasons for managing the lifetime of JacobObjects on a per thread basis. Jacob normally manages the the com/Java
  137. object lifetime as described in the
  138. <a href="JacobComLifetime.html">JacobComLifetime.html</a> document. Some users have run into situations where they wish to try and let the Java GC lifetime
  139. manage the lifetime of objects. This seems to usually be tied to long running threads or to objects created as part of
  140. event callbacks. Code was added to let users try and let the JVM manage the object life cycles even though the
  141. <a href="JacobComLifetime.html">JacobComLifetime.html</a> document says this is a bad idea. Added 1.9.
  142. <p></p>
  143. This value is cached at startup and cannot be changed on-the-fly via
  144. <code>System.setProperty();</code>
  145. <p></p>
  146. The default value is
  147. <em>false</em>
  148. <p></p>
  149. Example:
  150. <code>-Dcom.jacob.autogc=false</code>
  151. </td>
  152. </tr>
  153. <tr>
  154. <td>&nbsp;&nbsp;&nbsp;</td>
  155. <td valign="top">
  156. <h4>com.jacob.includeAllClassesInROT</h4>
  157. </td>
  158. <td>
  159. Acts as master switch for and &ltclass_name&gt.PutInROT. This property determines if the (experimental) PutInROT property
  160. is even checked. It was added in version 1.15 because the property check in PutInROT brok applets because they are not
  161. allowed to check system properties at run time. com.jacob.includeAllClassesInROT is checked at class initialization which
  162. is allowed.
  163. <p>The default value of this flag is
  164. <i>true</i> which matches all behavior prior to 1.13 and the default behavior for 1.13 on</p>
  165. <p>Setting this flag to false causes Jacob to check the and &lt;class_name&gt;.PutInROT property for every Jacob object
  166. that is created.</p>
  167. </td>
  168. </tr>
  169. <tr>
  170. <td>&nbsp;&nbsp;&nbsp;</td>
  171. <td valign="top">
  172. <h4>&ltclass_name&gt.PutInROT</h4>
  173. </td>
  174. <td>
  175. Lets a program specify that instances of certain classes are to not be inserted into the ROT. This experimental (1.13) feature
  176. provides a mechanism for freeing VariantViaEvent objects that are created in Event threads. There is normally no way
  177. to free those objects because the thread terminates outside of any normally MTA/STA Startup/Teardown code. Each event
  178. occurs in a new thread and creates a new ROT entry so they grow without bounds.
  179. <p></p>
  180. This option may cause VM crashes in certain situations where windows memory is freed outside of the thread it was created
  181. in but empirical evidence shows there are situations where this great reduces the long running memory footprint of applications
  182. that process a lot of events.
  183. <em>This function is still experimental</em>. The functionality was added 1.13. Some of this overlaps the experimental
  184. <code>com.jacob.autogc</code> introduced in 1.9. See the ROT.java test program for an example of the effects of this option.
  185. <p> </p>
  186. This value is checked every time and can be changed on-the-fly via
  187. <code>System.setProperty();</code>
  188. <p> </p>
  189. Example:
  190. <code>System.setProperty("com.jacob.com.VariantViaVariant.PutInROT","false");</code>
  191. <BR> Example:
  192. <code>-Dcom.jacob.com.VariantViaVariant.PutInROT=false</code>
  193. </td>
  194. </tr>
  195. <tr>
  196. <td colspan=3>
  197. <h3>Debugging and Troubleshooting</h3>
  198. </td>
  199. </tr>
  200. <tr>
  201. <td>&nbsp;&nbsp;&nbsp;</td>
  202. <td valign="top">
  203. <h4>com.jacob.debug</h4>
  204. </td>
  205. <td>
  206. Determines if debug output is enabled to standard out.
  207. <p> </p>
  208. This value is cached at startup and cannot be changed on-the-fly via
  209. <code>System.setProperty();</code>
  210. <p></p>
  211. The default value is
  212. <strong>false</strong>
  213. <p></p>
  214. Example:
  215. <code>-Dcom.jacob.debug=false</code>
  216. </td>
  217. <tr>
  218. <tr>
  219. <td>&nbsp;&nbsp;&nbsp;</td>
  220. <td valign="top">
  221. <h4>-XCheck:jni</h4>
  222. </td>
  223. <td>
  224. This turns on additional JVM checking for JNI issues. This is not an actual JACOB system property but a property used by
  225. the JVM.
  226. <p></p>
  227. The default is "no additional checking" Example:
  228. <code>-XCheck:jni</code>
  229. </td>
  230. </tr>
  231. </table>
  232. <hr>
  233. <h2>Finding the DLL version using windows command line</h2>
  234. The jacob.dll file includes the jacob release number in the version field. Run the following from the command prompt
  235. <code>dumpbin /version jacob.dll</code> . The dll version number is stored in the "image version" field of the "OPTIONAL HEADER VALUES" section. This information
  236. from
  237. <a href="http://msdn2.microsoft.com/en-gb/library/h88b7dc8(VS.71).aspx">
  238. The Microsoft msdn web site</a>
  239. <hr>
  240. <h2>Unit Tests</h2>
  241. Jacob must know the location of the DLL when running the unit tests in Eclipse. The simplest way to do this is to add the
  242. dll path to the unit as a VM argument. The argument should be specified based on where you installed the jacob source package.
  243. If you have jacob unpacked in c:/dev/jacob and built using build.xml, then the vm arguments would be:
  244. <br>
  245. <code>-Djava.library.path=c:/dev/jacob/release/x86</code> .
  246. <p></p>
  247. Last Modified 4/2008 1.15
  248. </BODY>
  249. </HTML>