Many Jars

Merry Christmas! :wink:

I’d like to spend a few minutes of this holiday here to ask you about a doubt in my project . The situation is very simple: I have a Jar file that contains the whole game rules, IA, monsters etc, and many other Jar files named “Enviroments”. The user has the first Jar, but it alone doesn’t work, it needs at least one enviroment to run the game. It’s necessary to place at least one of the jar files in the same package of the game (for example, c:/theGame). My problems reside in this point:

a. The game Jar need to look in the directory for compatible enviroments Jars. How it can do that?

b. After that, the game must acess the Jar’s objects. How it can do that?

You can use an URLClassloader (http://java.sun.com/j2se/1.4.2/docs/api/java/net/URLClassLoader.html) for that or you could use blahs class locator: http://www.java-gaming.org/forums/index.php?topic=9240.0

What do you mena by access?

You have two choices in genreal foir getting data out of jars:
(1) Use a class loader and getResourceAsStreaM()
(2) Open it with JarInputFIle and and acess JarEntries directly.

If you want to actually create objects from classes in the jar file, you need to do #1.

As for associateing the Jars, thats totally up to you. You coudl have a third file that contaisn the associations, you could put a custoim entry in the Jar’s manifest, or you could have a well known Class or Interface type/name that you seach for and fetch the data from.

For how to do the third, you can look at how the Plugins mechanism works in JUtils.