dominoGuru.com
Your Development & Design Resource
XPages, Java Runtimes, and Windows OS-level interaction via native cmd.exe Calls
09/21/2010 11:50 AM by Chris Toohey
While responding to questions received via email, through Facebook and Twitter, I came across a question that I thought would make a good article.
The basic gist of the question is this: is there a way to call a Windows OS application via a Lotus Notes Client XPage?
The developer looking for a solution was attempting to use JavaScript to call an ActiveX Control to execute a local method call... but there's another way.
The Plan: use a Java method to call a Windows OS-level xcopy.exe.
(As Nathan points out, the Java File methods are the more desired approach for performing xcopy-style operations as it's not only more flexible but multi-OS compatible... but not only is this an illustrative example showing that Windows OS native cmd.exe calls are possible, but I plan on publishing another article and app using the Java File methods soon.)
First, we'll create our simple Java file (xwinos.java):
You can use any Java-friendly authoring tool (Eclipse, Aptana, et al) or even Notepad to create the above xwinos.java, which you can save on your desktop (any directory, really).
Once you have your xwinos.java, you'll want to import it into the NSF and include it in the XPage Build Path. In an attempt to not repeat myself, follow the steps outlined in this article for adding a Java Script Library to the Project Build Path.
Once included in the Build Path, your Java Script Library will be available for import/use in an SSJS Script Libary:
importPackage(com.dominoguru.xwinos);
function interact() {
xwinos.xcopy();
}
Now, you're ready for the XPage...
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.resources>
<xp:script src="/functions.jss" clientSide="false"></xp:script>
</xp:this.resources>
<p style="margin:
25px;">
<xp:button value="Interact!" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:executeScript script="#{javascript:interact();}">
</xp:executeScript>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</p>
</xp:view>
This XPage Souce XML will produce a very simple but functional XPage:
Once the Interact! button is clicked, the xwinos.xcopy
method is called and -- as written -- all contents from the C:\source
directory will be copied to the C:\target directory.
Example/Download
XWinOS, the above example NotesDatabase, includes the Java, SSJS, and XPage designs discussed in the above article.