Short version: Can I omit a class from a JAR file (knowing that that class is never actually used) without the JVM throwing a NoClassDefFoundError exception?
Longer version: My game includes within it a couple of mini-games that I've set up so that they can be played as stand-alone games. Now, the JAR file for the full game is quite big, so I'm thinking that for the stand-alone mini-games I should be able to put them in much smaller JAR files by omitting the unused classes. Trouble is, I can't simply omit classes from the JAR (classes that are mentioned, but that I know are never actually used) because the JVM still tries to load them.
A bit of reading up (http://java.sun.com/docs/books/jls/third_edition/html/execution.html
) tells me that when the JVM loads a new class, it is optional whether or not it resolves all of the other class names mentioned by the loaded class, and how deep it goes in recursing this. In principle, a JVM could complete the recursion and load up every class mentioned in the JAR as soon as it is launched ("static resolution").
So, my question is whether it's possible to tell the JVM not to load a class (and, specifically, not to throw a NoClassDefFoundError if the class cannot be loaded) until that class is explicitly used.
(I had thought it was possible to do this by calling the Class.forName("MyClass") method, and catching the exception at that point, but that doesn't seem to stop the JVM still trying to load the class at a later time.)
Does this make sense to anyone, or am I talking complete gibberish?
Thanks for any suggestions!