Using my own library in Interpreted Java scripts

I am getting into the swing of screen-scraper now. :) I have started to refactor some scripts and wanted to take a simple approach of putting common routines into a library I can call from any of my scripts.

Can I use a source library that my scripts could include? (Simplest!)

Or, do I have to compile a jarfile for JRE 1.4.2?

If so what's the simplest way to start doing that - I want to include calls to various screen-scraper built-ins so I would need to get CLASSPATH correct etc.

Pete
- Not quite a newbie.

insight from Jan

I wanted to have libraries of my own routines, the only thing I could find of relevance on your site was this above forum thread which basically said 'we don't know'.
If it's of any use I've sussed it. At the top of each script needing the library you need this:

import bsh.Interpreter;
source("C:\\Documents and Settings\\me\\Desktop\\LIBS\\lib.txt");

where the import statement is necessary for the source() bit that follows, and the source() statement itself must specify a path to a text file which it effectively includes.

Here are the first few lines of my lib.txt:

------------
import java.text.*;
import java.util.*;
import java.util.regex.*;

openReadableFile(String fname)
{
File inputFile = new File(fname);
FileReader in = new FileReader( inputFile );
BufferedReader buffRead = new BufferedReader( in );
return buffRead;
}

// .. and more
-----------

It works, finally!
Obviously this is for beanshell only (although I've used a similar trick with javascript using eval).

HTH and saves other people some hours (newbie to beanshell BTW)

cheers

jan

Using my own library in Interpreted Java scripts

Hi,

Assuming you're using Interpreted Java, you might peruse the documentation for that scripting language ( http://www.beanshell.org/manual/contents.html) to see if you can spot a simple way to include code.

Alternatively, if you're willing to go the compiled Java route, take a look at the "Working with external Java libraries" on this page: http://www.screen-scraper.com/support/docs/using_scripts.php. The CLASSPATH issue is fairly simple, fortunately. You just need to drop your jar into screen-scraper's lib/ext folder, and it will get added automatically. Just be sure you're compiling your code to be compatible with Java 1.4.2.

Don't hesitate to post a reply if we can help further.

Kind regards,

Todd Wilson