[jsword-devel] Java Web Start and loading resources

DM Smith dmsmith at crosswire.org
Tue Feb 19 12:56:30 MST 2013


On Feb 19, 2013, at 1:59 PM, Chris Burrell <christopher at burrell.me.uk> wrote:

> I haven't come across this one before. I've come across an issue in Java 7 where it starts catering for INDEX.LIST files if they are packaged into jar dependencies whereupon it tries to get every dependency in there (the INDEX.LIST is located under META-INF).
> 
> But if you mean resources as in the ones under src/main/resources which end up on the classpath, I'm not entirely sure why they can't be found. 
> 
> Can it be anything to do with this: http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/faq.html#s211

Probably. Was looking at that before I posted this.

> 
> The javadoc for pickLoader in CwClassLoader is a bit misleading in terms of it saying "returns true ..." but I'm not sure I really understand the logic. But I'm guessing it's getting the System classloader at some point in the chain, and then you end up not finding your resources?
> 
> Why are we using our own classloader by the way?

A simple example of how we use it and then an explanation of how it is useful:
In the jar for BibleDesktop, we have desktop.properties, which is the default set of properties for BibleDesktop.
The user can change these properties, so we save them to disk (under $JSWORD_HOME, which varies by OS. Under linux it is ~/.jsword and mac it is ~/Library/Application Support/JSword).

Now we have two files named desktop.properties. Rather than having a file lookup in $JSWORD_HOME and then a resource lookup in the jar, we have a single mechanism to do the lookup and we prefix $JSWORD_HOME to the lookup path for the classloader. This then provides merely a resource lookup as a singular mechanism to get the file.

The advantage of this is that any text file that is loaded by the CWClassLoader can now be overridden by dropping a copy of a file into $JSWORD_HOME. This file can be represented in several different ways:

If the class owning the resource InstallManager.plugin is org.crosswire.jsword.book.install.InstallManager, then the file can be any of the following:
$JSWORD_HOME/InstallManager.plugin
$JSWORD_HOME/org.crosswire.jsword.book.install.InstallManager.InstallManager.plugin
$JSWORD_HOME/org/crosswire/jsword/book/install/InstallManager/InstallManager.plugin
Then it looks in the jars on the classpath for the same.

I forget the lookup order, but it takes the first it finds. Let's just say that it is bad form to have it in two places locally.

Then editing the file allows for those values to take effect on next startup.

This is really useful to change logging levels by dropping CWLogging.properties into JAVA_HOME and setting it up the way you want. (So it is useful to developers to tweak JSword and not have those changes accidentally managed under source code control.)

Another example, the language Sorani was not being recognized as a right-to-left language (because the language was unknown to JSWORD). We could ship the end user an updated iso639.properties file for them to drop in JSWORD_HOME. And then it would work.

The disadvantage to all of this is that there is no reset button. The file takes precedence over all future updates to JSword. So when the program is updated to handle the work-around and perhaps to also provide new stuff, the file takes precedence.

We had the program launcher include $JSWORD_HOME on the classpath, but that didn't work well for all platforms as the path varies significantly on Windows from one OS version to the next and on one user setup to the next.

Since JSword is able to figure it out, it essentially adds the correct value of JSWORD_HOME to the classpath by providing its own classloader.

If I remember correctly, this mechanism was necessary to get WebStart to work, too. Now it doesn't work.

Clear as mud?

In Him,
	DM

> Chris
> 
> 
> 
> On 19 February 2013 13:25, DM Smith <dmsmith at crosswire.org> wrote:
> We've always provided a way to run Bible Desktop directly from the web using Java Web Start.
> 
> Now we're having problems. There's a change that prevents our code from finding resources. It appears that Java 7's Web Start is preventing our ClassLoader from loading resources.
> 
> I'd greatly appreciate help finding this.
> 
> I'm thinking it may be a problem in other contexts.
> 
> The exact same code runs from the command line.
> 
> In Him,
>         DM
> 
> 
> 
> _______________________________________________
> jsword-devel mailing list
> jsword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/jsword-devel
> 
> _______________________________________________
> jsword-devel mailing list
> jsword-devel at crosswire.org
> http://www.crosswire.org/mailman/listinfo/jsword-devel

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.crosswire.org/pipermail/jsword-devel/attachments/20130219/864b0eb9/attachment-0001.html>


More information about the jsword-devel mailing list