Applets - using javac on class files

Hey all,

In a game I’m working on I want to be able to serve downloadable content, and I figure one of the best ways of doing that without having to recreate the main JAR is to make use of javac to compile class files on the fly (at least for logic updates).

I’m just wondering if anybody has done this with an Applet before and how they’ve done it? In a local application I would just be saving the class file to their disk somewhere and then would execute it as normal, but the whole sandbox thing makes it all more difficult.

Would it make more sense to just have like a DLC.jar that is only class files and I can update as I want without the user having to see it?

Overall I’m pretty much a noob when it comes to applets, and I’m trying to change that. So thanks in advance for the help and advice.

Just provide the downloadable content as compiled class files. I don’t see any benefit to providing Java code that the applet compiles – it will compile to the same bytecode. You can code to interfaces, etc and have the downloadable portion plug in. URLClassLoader will load classes from a remote JAR file.

Since you’re running an applet, and the user will get the latest application code anyway, why not just add the new functionality to your game jar and enable/disable it as appropriate?

My only thought on that was because if I change the main JAR it will potentially take a long time for the user to redownload everything. But now that I think about it as long as I keep expensive resources (images, sounds) in a separate JAR everything should be fine.

I agree that this is a bad idea, but in the interest of solving your original idea you could have the classes compiled on the server and then downloaded as .class files by the applet. The class loaders can load from an array of bytes (the class) and so you don’t need a place on the disk for the classes to be stored.

Yeah, the main reason I was thinking of keeping it separate was to make paid DLC stuff - like you get to download the extra bundle or whatever if you’ve paid. But I think just making all this server side code and just don’t allow the player to use it. That way they can still view another player using it if they want.