Jacob is a Java library that lets Java applications communicate with Microsoft Windows DLLs or COM libraries. It does this through the use of a custom DLL that the Jacob Java classes communicate with via JNI. The library and dll isolate the Java developer from the underlying windows libraries so that the Java developer does not have to write custom JNI code. (Jacob是一个Java库,可让Java应用程序与Microsoft Windows DLL或COM库进行通信。它通过使用定制的DLL来实现此目的,Jacob Java类通过JNI与之通信。该库和dll将Java开发人员与基础Windows库隔离开,因此Java开发人员不必编写自定义JNI代码。)

Jacob is not used for creating ActiveX plugins or other modules that live inside of Microsoft Windows applications. (Jacob不用于创建ActiveX插件或Microsoft Windows应用程序内部的其他模块。)


The Jacob Packages (雅各布包)

The JACOB jar contains two main packages: the com.jacob.com.*> package and the com.jacob.activeX package. The com.jacob.com.* package contains classes map very closely to the com dispatch model with the com.jacob.com.Dispatch acting as the primary communication class. Dispatch operate as a function library with a set of static methods that map very closely to the C++ Dispatch APIs provided to the COM layer. (JACOB jar包含两个主要软件包:com.jacob.com。*>软件包和com.jacob.activeX软件包。 com.jacob.com。*软件包包含与com调度模型非常紧密地映射的类,其中com.jacob.com.Dispatch充当主要通信类。 Dispatch作为函数库运行,具有一组静态方法,这些方法非常紧密地映射到提供给COM层的C ++ Dispatch API。)

com.jacob.activex.ActiveXComponent can be used in place of Dispatch to provide a more object like API. The only exception to this guideline is that the ActiveXComponent class is always used to make the initial connection to the target dll/COM component. (com.jacob.activex.ActiveXComponent可以代替Dispatch使用,以提供更多类似于API的对象。该准则的唯一例外是,始终使用ActiveXComponent类与目标dll / COM组件进行初始连接。)


Considerations when doing server side automation of office (做办公室的服务器端自动化时的注意事项)

Most office and many windows client type applications are not written to be used in high volume or multi-threaded server environment. There is a support note on the Microsoft web site that discusses some of the issues. (大多数Office和许多Windows客户端类型的应用程序都不适合在大容量或多线程服务器环境中使用。 Microsoft网站上有一份支持说明,其中讨论了一些问题。)


Determining the API of the target application (确定目标应用程序的API)

Section not yet written. (本节尚未写。)


The Jacob DLL (雅各布DLL)

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 appropriate jacob dll into your path or use VM options to add directory holding jacob dll to the path. Prior to 1.14M6, the jacob DLL name was always "jacob.dll". This made it hard to verify jacob was loading the correct dll when multiple copies 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 the same tames. Starting in 1.14M6, Jacob's library loader selects a dll with the appropriate name based on the jacob release and platform. The dll naming convention is:
jacob<platform>.<version.>.dll (Jacob.jar依赖于从库路径或类路径加载的DLL文件。这意味着您必须将适当的jacob dll复制到路径中,或者使用VM选项将包含jacob dll的目录添加到路径中。在1.14M6之前,jacob DLL名称始终为“ jacob.dll”。当在单个系统上安装了多个jacob副本时,很难验证jacob是否正在加载正确的dll。在32位和64位dll具有相同驯服的64位系统上,这也令人困惑。从1.14M6开始,Jacob的库加载器会根据jacob版本和平台选择具有适当名称的dll。 dll的命名约定为:jacob <平台> 。 <版本。> 。dll)

Classloader issues

The code is written so that the jacob.dll is only loaded one time per classloader. This works fine in the standard application but can cause problems if jacob.jar is loaded from more than one class loader. This can happen in the situation where multiple jacob dependent web applications run in the same container like a web server or JWS runtime. In the case of a web server, Jacob is normally put in the application specific WEB-INF/lib directory. This is the "right" way to do it and works in most situations. But, if Jacob is put in the WEB-INF/lib directory of each application's war file for more than one application then a problem occurs. In this situation, the web server uses a different classloader for each application. This means that each application will attempt to load the jacob.dll and errors are generated. The only way around this at this time (1.11) is to put the jacob.jar in the common/lib because that classloader is inherited by all of the applications so the DLLs will only get loaded once. This problem is described in SF 1645463 and should be fixed in some future release, fix method and time not yet determined. (编写代码是为了使jacob.dll每个类加载器仅加载一次。这在标准应用程序中可以正常工作,但如果从多个类加载器中加载jacob.jar,则可能导致问题。在多个依赖于jacob的Web应用程序在同一容器(例如Web服务器或JWS运行时)中运行的情况下,可能会发生这种情况。对于Web服务器,通常将Jacob放在应用程序特定的WEB-INF / lib目录中。这是这样做的“正确”方法,并且在大多数情况下都可以使用。但是,如果将Jacob放在多个应用程序的每个应用程序war文件的WEB-INF / lib目录中,则会出现问题。在这种情况下,Web服务器为每个应用程序使用不同的类加载器。这意味着每个应用程序都将尝试加载jacob.dll并生成错误。此时(1.11)的唯一解决方法是将jacob.jar放在common / lib中,因为该类加载器被所有应用程序继承,因此DLL仅被加载一次。 SF 1645463中描述了此问题,此问题应在将来的某些发行版中修复,修复方法和时间尚未确定。)


Microsoft Visual C++ library dependencies.(Microsoft Visual C ++库依赖项。)

Jacob 1.15 is build with VC++ 2005 statically linked into the DLL. This removes the need for a separate msvcr80.dll installation. (Jacob 1.15是使用静态链接到DLL的VC ++ 2005构建的。这样就无需单独安装msvcr80.dll。)

Jacob 1.13 is built with VC++ 2005 that creates a dependency on msvcr80.dll. Windows XP and later seem to already include the necessary components. NT/2000 and Server/2003 require that you download the Visual C 2005 redistributable package, vcredist_x86.exe from the Microsoft web site. Microsoft has a download available that supplies the necessary components. It is distributed as a redistributable package. (Jacob 1.13是使用VC ++ 2005构建的,该版本在msvcr80.dll上创建了依赖项。 Windows XP和更高版本似乎已经包含必需的组件。 NT / 2000和Server / 2003要求您从Microsoft网站下载Visual C 2005可再发行程序包vcredist_x86.exe。 Microsoft提供了一个下载文件,其中提供了必要的组件。它作为可重新分发的软件包分发。)

If you see the following message then you probably don't have the right C++ libraries. (如果看到以下消息,则可能是您没有正确的C ++库。)

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\apps\...\jacob.dll: This application has 
failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem 


Visual C redistributable installer SP1


Jacob Command Line Settings(Jacob命令行设置)

This library supports several different command line options: (该库支持几种不同的命令行选项:)

dll path location and dll name customization

   

java.library.path

Standard Java property used to add the location of the jacob dll to the JVM's library path. (Added 1.11)

Example: -Djava.library.path=d:/jacob/release/x86 (示例:-Djava.library.path = d:/ jacob / release / x86)

   

jacob.dll.name

Override the standard DLL name with a custom one. This stops jacob from using its 32bit/64bit detection and dll rendezvous logic. Sometimes used when Jacob is bundled with another application and the application wishes to tie the jacob dll version number to the application version number. (Added 1.14M7)

Example: -Djacob.dll.name=MyFunkyDllName.dll (示例:-Djacob.dll.name = MyFunkyDllName.dll)

   

jacob.dll.name.x86 & jacob.dll.name.x64

Override the standard 32 bit DLL name with custom ones. Sometimes used when Jacob is bundled with another application and the application wishes to tie the jacob dll version number to the application version number. (Added 1.14M7)

Example to override 32 bit dll name: -Djacob.dll.name.x86=MyFunkyDllName-32bit.dll (覆盖32位dll名称的示例:-Djacob.dll.name.x86 = MyFunkyDllName-32bit.dll)

Memory Management

   

com.jacob.autogc

Determines if automatic garbage collection is enabled. This is the only way to free up objects created in event callbacks. Automatic garbage collection , based on Java gc rules, garbage collection can be enabled via the com.java.autogc command line option. This feature was added in release 1.9 is not fully debugged.

There are real reasons for managing the lifetime of JacobObjects on a per thread basis. Jacob normally manages the the com/Java object lifetime as described in the JacobComLifetime.html document. Some users have run into situations where they wish to try and let the Java GC lifetime manage the lifetime of objects. This seems to usually be tied to long running threads or to objects created as part of event callbacks. Code was added to let users try and let the JVM manage the object life cycles even though the JacobComLifetime.html document says this is a bad idea. Added 1.9. (确实有理由在每个线程的基础上管理JacobObjects的生存期。 Jacob通常按照JacobComLifetime.html文档中的描述管理com / Java对象的生存期。一些用户遇到了希望尝试让Java GC生命周期管理对象生命周期的情况。这似乎通常与长时间运行的线程或作为事件回调的一部分创建的对象有关。添加了代码,使用户可以尝试让JVM管理对象生命周期,即使JacobComLifetime.html文档说这是个坏主意。增加了1.9。)

This value is cached at startup and cannot be changed on-the-fly via System.setProperty(); (此值在启动时缓存,并且无法通过System.setProperty()即时更改。)

The default value is false (默认值为false)

Example: -Dcom.jacob.autogc=false (示例:-Dcom.jacob.autogc = false)

   

com.jacob.includeAllClassesInROT

Acts as master switch for and &ltclass_name>.PutInROT. This property determines if the (experimental) PutInROT property is even checked. It was added in version 1.15 because the property check in PutInROT brok applets because they are not allowed to check system properties at run time. com.jacob.includeAllClassesInROT is checked at class initialization which is allowed.

The default value of this flag is true which matches all behavior prior to 1.13 and the default behavior for 1.13 on(该标志的默认值为true,它匹配1.13之前的所有行为以及1.13上的默认行为。)

Setting this flag to false causes Jacob to check the and <class_name>.PutInROT property for every Jacob object that is created.(将此标志设置为false会导致Jacob检查每个创建的Jacob对象的和 .PutInROT属性。)

   

&ltclass_name>.PutInROT

Lets a program specify that instances of certain classes are to not be inserted into the ROT. This experimental (1.13) feature provides a mechanism for freeing VariantViaEvent objects that are created in Event threads. There is normally no way to free those objects because the thread terminates outside of any normally MTA/STA Startup/Teardown code. Each event occurs in a new thread and creates a new ROT entry so they grow without bounds.

This option may cause VM crashes in certain situations where windows memory is freed outside of the thread it was created in but empirical evidence shows there are situations where this great reduces the long running memory footprint of applications that process a lot of events. This function is still experimental. The functionality was added 1.13. Some of this overlaps the experimental com.jacob.autogc introduced in 1.9. See the ROT.java test program for an example of the effects of this option. (在某些情况下,此选项可能会导致VM崩溃,在这种情况下,Windows内存在创建该线程的线程之外被释放,但是经验证据表明,在某些情况下,这种情况会极大地减少处理大量事件的应用程序的长期运行内存占用。此功能仍处于实验阶段。该功能已添加1.13。其中一些与1.9中引入的实验性com.jacob.autogc重叠。有关此选项的效果的示例,请参见ROT.java测试程序。)

This value is checked every time and can be changed on-the-fly via System.setProperty(); (每次都会检查此值,并且可以通过System.setProperty()即时更改。)

Example: System.setProperty("com.jacob.com.VariantViaVariant.PutInROT","false");
Example: -Dcom.jacob.com.VariantViaVariant.PutInROT=false (示例:System.setProperty(“ com.jacob.com.VariantViaVariant.PutInROT”,“ false”);示例:-Dcom.jacob.com.VariantViaVariant.PutInROT = false)

Debugging and Troubleshooting

   

com.jacob.debug

Determines if debug output is enabled to standard out.

This value is cached at startup and cannot be changed on-the-fly via System.setProperty(); (此值在启动时缓存,并且无法通过System.setProperty()即时更改。)

The default value is false (默认值为false)

Example: -Dcom.jacob.debug=false (示例:-Dcom.jacob.debug = false)

   

-XCheck:jni

This turns on additional JVM checking for JNI issues. This is not an actual JACOB system property but a property used by the JVM.

The default is "no additional checking" Example: -XCheck:jni (缺省值为“不进行其他检查”。示例:-XCheck:jni)


Finding the DLL version using windows command line(使用Windows命令行查找DLL版本)

The jacob.dll file includes the jacob release number in the version field. Run the following from the command prompt (jacob.dll文件的版本字段中包含jacob发行版号。从命令提示符处运行以下命令)

dumpbin /version jacob.dll

. The dll version number is stored in the "image version" field of the "OPTIONAL HEADER VALUES" section. This information from (。 dll版本号存储在“可选标题值”部分的“映像版本”字段中。此信息来自)

The Microsoft msdn web site


Unit Tests(单元测试)

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 dll path to the unit as a VM argument. The argument should be specified based on where you installed the jacob source package. If you have jacob unpacked in c:/dev/jacob and built using build.xml, then the vm arguments would be: (在Eclipse中运行单元测试时,Jacob必须知道DLL的位置。最简单的方法是将dll路径作为VM参数添加到设备。应该根据jacob源软件包的安装位置指定参数。如果您在c:/ dev / jacob中解压了jacob并使用build.xml进行了构建,则vm参数将为:)


-Djava.library.path=c:/dev/jacob/release/x86

. (.)

Last Modified 4/2008 1.15 (上次修改时间4/2008 1.15)