How to make "Global" vars shared between custom JAR and ScreenScraper
I am calling ScreenScraper from my own Java JAR, but am having problems getting the JAR and ScreenScraper to share the same "global" variables. (I know there is no such thing as global variables in Java - I mean members of a Singleton class.)
My.jar contains (among other things):
- Global.java (singleton with private static members, public static getInstance() and and static getters/setters)
- Runner.java (instatiates a RemoteScrapingSession and scrapes it)
The jar is placed in C:\Program Files\screen-scraper professional edition\lib\ext and I execute the jar from there.
The Runner runs, calling the scraping session.
The problem is that Runner and ScreenScraper are each creating their own instance of Global -- so that the members in there are not really global. Is this because ScreenScraper is really running in its own Java process? and not the Java process that Runner is running in?
How do I achieve this idea of shared/"global" variables between the JAR and ScreenScraper?
Solved by using a shared read-writeable properties file
I solved this issue by using a shared read-writeable properties file.
My.jar contains (among other things):
- MyVariableProperties.java (singleton with an inner class that extends Properties with getter and setter; both getter and setter always get latest info from C:\MyVariable.properties)
- Runner.java (instantiates a RemoteScrapingSession and scrapes it)
My deployment script deploys the following to the C: drive
- MyVariable.properties (contains the "global" variables/properties I want My.jar and ScreenScraper to share)
My.jar is placed in C:\Program Files\screen-scraper professional edition\lib\ext and I execute the jar from there.
The Runner runs, calling the scraping session.
Both Runner and the ScreenScraper scripts can read and write to C:\MyVariable.properties using MyVariableProperties class.