Using iMacros with JAVA (via the Jawin package) in Eclipse

Share your tips, tricks and favorite iMacros macros, scripts and applications for web automation in general here.

Moderator: iMacros Moderators

Using iMacros with JAVA (via the Jawin package) in Eclipse

by Hannes, Tech Support on Tue Feb 13, 2007 6:46 am

[Update 2010-08-23]
The Jawin library does not support 64bit. However, there's a replacement called JACOB (http://sourceforge.net/projects/jacob-project/). It's pretty easy to use and the main steps given below still hold. Just replace any reference to jawin with the appropriate JACOB one. Additionally, I have posted a small HowTo here.
[End of update]

[Update]
When running iMacros from Java, you may also be interested in using the iMacros Java wrapper class: http://forum.iopus.com/viewtopic.php?f=14&t=1147
[End of update]

[update]
A tutorial for using NetBeans instead of Eclipse can be found here: http://forum.iopus.com/viewtopic.php?f=6&t=7183
[End of update]



Preliminaries:

1) Download Jawin (http://jawinproject.sourceforge.net/, version 1.0.19, released under this license: http://jawinproject.sourceforge.net/LICENSE.txt), extract to local folder
[Update] Version 2.0-alpha1 also works fine.[End of update]

2) Start Eclipse

Start new project (usign jawin) in Eclipse:

1) File --> New --> Project

Image

2) Java --> Java Project --> Next

Image

3) Enter name: "iMacrosScriptingInterface" --> Next

4) Libraries --> Add External Jars" --> select jawin.jar from the Jawin\lib directory --> Finish

Image

5) Right-click iMacrosScriptingInterface in Package Explorer tab

Image

6) Import --> General --> File System --> Next

Image

7) Browse --> jawin-dir\bin\jawin.dll --> Finish

New Class in project

1) Select iMacrosScriptingInterface in the Package Explorer tab

2) File --> New --> Class

Image

3) Name: iMacrosTest --> Finish

Writing/Runnign an example

1) Open iMacrosTest.java

2) Copy the following code to iMacrosTest.java:

Code: Select all
//This code makes use of jawin from http://jawinproject.sourceforge.net/
//jawin license: http://jawinproject.sourceforge.net/LICENSE.txt

//two imports from jawin.jar
import org.jawin.DispatchPtr;
import org.jawin.win32.Ole32;

public class iMacrosTest {

   public static void main(String[] args) {
      try {
         Ole32.CoInitialize();

         DispatchPtr app = new DispatchPtr("imacros");

         //Calling iMacros methods
         app.invoke("iimInit", null);
         app.invoke("iimPlay", "CODE:URL GOTO=http://www.iopus.com");
         app.invoke("iimPlay", "CODE:TAG POS=1 TYPE=A ATTR=TXT:iMacros EXTRACT=TXT");

         //manually cast return values to correct type
         String iret = app.invoke("iimGetLastExtract").toString();

         app.invoke("iimExit");
                        System.out.println(iret);
                       
         Ole32.CoUninitialize();
      }

      catch (Exception e){
         e.printStackTrace();
      }

   }
}
[Edit: changed "URL GOTO=www.iopus.com" to "URL GOTO=http://www.iopus.com]
[Update]Changed TAG command to comply with web page layout.[End of update]

3) You might want to select the full code and have it automatically be indented with "CTRL-i"

4) Menu: Run --> Run...

Image

5) Rightclick Java-Application --> New

Image

6) Under "Classpath" you should find the jawin.jar

Image

7) Under "Common" check both Debug and Run

Image

8) Click Run
this can later be accessed by the Run-Button:

Image

The Java class will now be compiled and started. It will open an iMacros browser window that visits http://www.iopus.com
Last edited by Hannes, Tech Support on Mon Aug 23, 2010 1:39 am, edited 2 times in total.
Reason: Added link to NetBeans tutorial
Hannes, iOpus Support
Hannes, Tech Support
 
Posts: 2119
Joined: Thu Sep 21, 2006 6:27 am

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by killer_mpg on Mon Mar 17, 2008 5:59 pm

Does this work with linux?
killer_mpg
 
Posts: 9
Joined: Tue Mar 11, 2008 5:56 pm

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by Hannes, Tech Support on Tue Apr 29, 2008 2:46 am

For Firefox, you can use the JavaScript Scripting Interface: http://wiki.imacros.net/iMacros_for_Firefox#Javascript_Scripting_Interface
Hannes, iOpus Support
Hannes, Tech Support
 
Posts: 2119
Joined: Thu Sep 21, 2006 6:27 am

Files

by Hannes, Tech Support on Fri May 02, 2008 3:30 am

The attached ZIP contains the full Eclipse workspace folder for the project.
(You may probably need to adjust the paths.)
Attachments
iMacrosScriptingInterface.zip
(81.08 KIB) Downloaded 2156 times
Hannes, iOpus Support
Hannes, Tech Support
 
Posts: 2119
Joined: Thu Sep 21, 2006 6:27 am

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by sothy1962 on Mon Jun 30, 2008 1:21 pm

Silly question, but is the expectation that one builds the jawin.jar file as it was not in the download?
sothy1962
 
Posts: 0
Joined: Mon Jun 30, 2008 1:13 pm

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by Hannes, Tech Support on Mon Jun 30, 2008 11:54 pm

If you download the binary 1.0.19 (jawin-1.0.19.zip, you will probably need to scroll down on that page), you will find the "jawin.jar" in "jawin-1.0.19/lib".
Hannes, iOpus Support
Hannes, Tech Support
 
Posts: 2119
Joined: Thu Sep 21, 2006 6:27 am

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by talz13 on Mon Dec 01, 2008 12:00 pm

Is there any way to use full java scripting under linux? Jawin is only for windows as far as I can see. I found j-interop on google, but don't know if that can take the place of jawin.
talz13
 
Posts: 8
Joined: Mon Dec 01, 2008 11:58 am

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by Tech Support on Mon Dec 01, 2008 3:17 pm

Currently, the iMacros Scripting Interface works only on Windows OS, however you can use popular "Linux" languages such as Perl, Python, PHP or Ruby to script it on Windows. Of course, iMacros also runs well on a virtual machine that you can host on your Linux server.

We plan to release a native Linux version in 2009. If you are interested in beta-testing such a version please email info AT iopus.com and we will notify you once the first beta is available.

Last but not least, you can already use iMacros for Firefox on Linux and control the browser via the command line interface:
http://wiki.imacros.net/iMacros_for_Fir ... ne_Support
User avatar
Tech Support
 
Posts: 4996
Joined: Tue Sep 20, 2005 12:25 pm

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by Hannes, Tech Support on Mon Apr 27, 2009 11:07 am

Please cf. the answer above.
Hannes, iOpus Support
Hannes, Tech Support
 
Posts: 2119
Joined: Thu Sep 21, 2006 6:27 am

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by srinivas on Mon Jul 13, 2009 12:50 am

Hi , I used the same code to test.I follow the same steps what it was mentioned in the above.But it was not working. I got the output as VT_BSTR .
can any one tell me the solution.
srinivas
 
Posts: 1
Joined: Mon Jul 13, 2009 12:42 am

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by Hannes, Tech Support on Mon Jul 13, 2009 6:13 am

Hannes, iOpus Support
Hannes, Tech Support
 
Posts: 2119
Joined: Thu Sep 21, 2006 6:27 am

Re: Using iMacros with JAVA (via the Jawin package) in Eclipse

by richermartyn on Tue Sep 08, 2009 4:38 am

Thank you for providing a information about Eclipse and I have download this url and I have installed in my system I follow such steps which you given over here. It's working Properly.
richermartyn
 
Posts: 0
Joined: Tue Sep 08, 2009 4:33 am

Running from the command line

by Hannes, Tech Support on Tue Aug 17, 2010 4:31 am

When run from the command line, both locations of the jawin library/binary (jawin.jar and the folder of jawin.dll) must be given in "classpath" and "java.library.path", respectively.

Given that both, the eclipse project and the jawin folder reside in c:\users\name\eclipse.workspace, here's how the command line calling "DownloadTest.class" looks like:

Code: Select all
C:\Users\name\eclipse.workspace\iMacrosJavaDownloadTest\bin>java -classpath C:\Users\name\eclipse.workspace\iMacrosJavaDownloadTest\bin;C:\Users\name\eclipse.workspace\iMacrosJavaDownloadTest\res\jawin-2.0-alpha1\lib\jawin.jar -Djava.library.path=c:\users\name\eclipse.workspace\jawin-2.0-alpha1\bin DownloadTest
Hannes, iOpus Support
Hannes, Tech Support
 
Posts: 2119
Joined: Thu Sep 21, 2006 6:27 am

Re: Using iMacros with JAVA (via the Jawin package) in Eclip

by Hannes, Tech Support on Mon Aug 23, 2010 1:40 am

The Jawin library does not support 64bit. However, there's a replacement called JACOB (http://sourceforge.net/projects/jacob-project/). It's pretty easy to use and the main steps given in the initial post still hold. Just replace any reference to jawin with the appropriate JACOB one. Additionally, I have posted a small HowTo here.
Hannes, iOpus Support
Hannes, Tech Support
 
Posts: 2119
Joined: Thu Sep 21, 2006 6:27 am


Return to How-To's and useful iMacros: All other topics

Who is online

Users browsing this forum: No registered users and 0 guests

Website Monitoring