Message-ID: <529859851.1339.1406237423512.JavaMail.email@example.com> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_1338_1892224382.1406237423511" ------=_Part_1338_1892224382.1406237423511 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
Scriptom is an optional Groovy module originally develo= ped by Guillaume Laforge. It combines the elegant "syntac= tical sugar" of Groovy with the power of the Jacob library (Java COM Bridge). Scriptom lets you use ActiveX or COM Windows components from Groovy. The re= sult is something that looks eerily similar to VBScript - onl= y groovier.
You can use Scriptom to automate Word = or Excel documents, control Internet Explorer, make your PC talk using the Microsoft Speech API, mo= nitor processes with WMI (Windows Management Instrumentati= on), or browse the Windows Registry using WShell= strong> - and much more. Scriptom also provides an e= asy way to talk to custom VB6 or Microsoft.NET libraries.
Of course, Scriptom can be used only on Microso= ft Windows.
Scriptom is included as an option in the Windows Installer, and Scriptom can be download= ed from this page (see below). The Scriptom codebase = is stable and feature-complete. The Jacob project -&= nbsp;Scriptom's foundation - was started = in 1999 and is being used in countless production Java applications worldwi= de. Scriptom is now in wide use as well, and ha= s proven to be stable and mature.
Scriptom gives you all the COM-scripti= ng power of Jacob, only it is a lot easier. See Getting Started with COM for= some tips to get you started.
The following are required to run Scriptom:
Maven-generated documentation is available at http://groovy.codehaus.org/modules/scriptom/1.6.0/index.html<= /a>. This contains useful information from the build, including JavaD= oc for all projects.
Scriptom is part of the Windows Installer= . If you are running Groovy scripts on Windows, you ar= e all set.
If you are running Groovy outside the Windows Installer= , and you aren't using Maven or Grape, yo= u probably just need the pre-packaged JAR files and associated binaries. Yo= u've come to the right place.
Note that as of release 1.6.0, the distribution archive= is formatted differently. The new format matches the folder structur= e needed by the Windows Installer. Source code, build scri= pts, and documentation are no longer included in the distribution.
You can add Scriptom to a Maven projec= t. Because there is JNI involved, it isn't quite as simple as adding a depe= ndency, but it is doable. Need to come up with an example of creati= ng an assembly with GMaven.
Add the Scriptom dependency to your Maven= strong>project.
Add the Jacob JAR dependency. This JAR must be load=
ed only once, so if you are working in a server application like To=
mcat or GlassFish, you need to ensure that
Jacob requires a DLL. It's a JNI project, after all= . But Jacob actually supports two versions of the DLL it n= eeds, one for 32-bit x86 systems, and one for the AMD x64 architecture (wor= ks with 64-bit Intel chips too). The easiest way to get this to work is to = put both DLLs somewhere on the system path. Jacob will aut= omatically pick the one it needs. Need to detail the other ways to = specify the Jacob DLL.
Need to detail the TLB projects, constants, etc.
Download the project archive and extract the files= .
Install the jar file and DLL file(s) into your project, and optionally i= nstall an update from Microsoft:
Add the Scriptom jar file (scriptom-1.5.4bX= -XX.jar) into your Java classpath. It contains both = Scriptom and Jacob class files, so you must not i= nclude jacob.jar.=20 =20
Copy both Scriptom-1.5.4bX-XX.dll files t= o somewhere on your java.library.path. (usually somew= here on the system 'PATH').=20 =20
To avoid the dreaded java.lang.UnsatisfiedLinkError= , download and install one of the following updates from Microsoft: Microsoft Visual C++ 2005 SP1 Redistributable Package (x86)= a>or Microsoft Visual C++ 2005 SP1 Redistributable Pack= age (x64). Scriptom doesn't support the = IA-64 (Itanium) architecture at this time, mainly= due to lack of interest. If you are wondering about the different processo= r architectures, check out the x86-64 wiki. It is usually= necessary to install these updates on Windows Server 2003= and Windows 2000, and we've found that it may also be nec= essary for Windows XP and even Vista.= =20 =20
Scriptom 1.5 is not supported for Groovy= 1.0 and earlier (Scriptom 1.2 is still available= ).
The project source is managed by Subversion. The projec= ts are already set up to work with Eclipse, but it isn't h= ard to get them working with other IDEs, and you can get by with Notepad. T= he project trunk is located at http://svn.c= odehaus.org/groovy/modules/scriptom/trunk. This is a Maven build. Because the tests are dependent on Windows tec= hnologies, there are some rather strange software requirements:
To build, use the following command line:
The latest build requires Groovy 1.5 or better.
Scriptom includes source files and compiled DLLs (Windo=
ws libraries compiled from C++) from Jacob version
1.14. You don't need to download sources and binaries =
from the Jacob project on SourceForge.net=
, though you can do so if you need to build the entire project yourself.
To build the project on Windows, run project
/build/make.bat. Since Scriptom is a =
Windows-specific module, there isn't a shell script for building on other o=
The build process requires Java 1.5 or higher (= Java 1.6 recommended) and ANT 1.6.5 or better.
Scriptom 1.5 is a substantial upg= rade to previous versions of Scriptom, and is not back= ward compatible. We hope you will agree that it is worth a littl= e code rework to get all these great new features! Scriptom 1.2 is the version that is documented in Groovy in Action.
Scriptom 1.5 is not backward compatible with previ= ous versions of Scriptom. To get your scripts runnin= g again, do this:
Let's say you want an application that talks. Pure Java implem=
entations aside (this is, after all, a Groovy/COM tutorial), and ignoring t=
he fact that the default voice on pre-Vista machines sounds like Dr. Zoidberg with a sinus infection, you could use the
You start by creating an ActiveXObject with the prog-id= for SpVoice. Now you can call any of the methods it suppo= rts. By default, SpVoice will block until it is done speak= ing, but we're also going to have it speak asynchronously and wait until it= is done.
If you have scripted COM before, you are probably used to using "ma= gic numbers" throughout your code in place of COM constants. In = this code sample, we're using fully-qualified constants instead.
Scriptom includes fully JavaDoc'd constant and interfac= e definitions from a number of commonly used type-libraries, and you can ev= en create your own. The source code for generating COM type libr= ary definitions for Groovy is written in Groovy , and it's included in the project. It may not seem like a big d= eal to replace a couple of numbers, but it will be a lot easier in 10 years= to find relevant information on SpeechVoiceSpeakFlags.SVSFlagsAsyn= c than on the number 1 (Google returns a little m= ore than 9 billion hits for the number '1', and about 1,000 for 'Speec= hVoiceSpeakFlags.SVSFlagsAsync,' including hits on this paragraph).&nb= sp; And besides, the code reads better.
Speaking of interfaces, it turns out that SpVoice suppo= rts several. You can test an ActiveXObject to see if= it supports a given interface using .supportsInterface, a= nd you can cast an ActiveXObject to a given interface usin= g .toInterface.
This next example displays the COM interfaces that SpVoice<= /strong> supports (within the SAPI library only):
|how not to crash the JVM or lock your process = td>|
|supported types and conversions in Java, VB6, an= d VB.NET|
|calling COM methods and properties from Groovy <= /td>|
|how to let methods change the value of passed-in= arguments|
|support for COM events|
Here is a simple example that uses the Microsoft ScriptControl= strong> to evaluate a JScript expression. This is a very i= ndirect way to add 2 and 2.
There are many, many potential uses for Scriptom -= far to many to try to maintain as part of this documentation. = So we've included a whole slew of meaty examples in the project archive for= you to play with. We'd like to encourage you to go look at thos= e examples, run them, and modify them. And if you come up with a= n especially interesting example, let us know about it. We may e= ven include it in a future release!
Some additional examples included with Scriptom:
Consuming Visual Basic 6 (VB6) and Visual Basic= .NET COM-enabled DLLs.
Articles about COM scripting in general, and
January 11, 2008
Tips for exploring COM libr= aries, finding documentation, etc.
December 3, 2007
Implement FIPS 140-1 compli= ant SHA-1 in Java with = Groovy, Scriptom, and Visual Basic.N= ET.
August 8, 2006
A short Microsoft Outlook e= xample.
March 17th, 2008
Siebel "business component" progra= mming
All known (unresolved) issues and feature requests are listed in the Scriptom Jira database.
Changes to each build are summarized in the Change Log.
Recent builds of Scriptom can be found here. Older versions are archive= d:
Build 10. Bundled with the Groovy 1.=
5 Windows Installer. Requires Groovy 1.5 and
(also Scriptom 1.1 and
Scriptom uses late binding. Visual Basic and VBA uses e= arly binding by default, but they also support late binding (with C= reateObject). If you are translating working Visual Basic code and= if your Scriptom code fails at the point where you've got= your call
(or whatever your object is) with an error message
then the chances are the progid "Sage...." that you are = using is the wrong one.
So you need to go and look in the registry to find what it might be. One= way to do this is with Microsoft's new Powershell cmd utility which you ca= n download from the ms web site. Install this and run the command line
It will produce a ream of different progids which you can sort and searc= h for one that looks a likely candidate. In my case it was SDOEngine.14
Alternatively if you have used the scriptom utility ExtractTlbInfo.groov= y to generate name maps for the com object you could read the source code f= or the (in my case SageDateObject140.java) class and you might find some co= de and/or comment like this:
Additionally, you can use the Object Browser included with Visu= al Basic (I recommend the one with VBA) to figure out possible progids and = then search the registry. This is a good way to associate interfaces = (and their methods) with a particular progid. If there are VBScri= pt or JScript examples available, they will include the corre= ct progids, since these languages are always late-bound.
If all else fails, hit the Groovy mailing lists. There are lots of= people out there with COM experience who can point you in the right direct= ion.