Question

I am making a very simple Java game using Pure Java! The game part is coming along very well. I have some people who are playing the game to test it for me. When ever there is an update I send them an email to download it. The whole game is just one jar file that you run straight off your desktop. This means that you are downloading the whole game in one file which takes quite a bit of time and that is not the first impression that I would like to give. And this brings me to my first question which is how to make a downloader! I want the player to download a Jar that is small in size and then run that to download a bigger Jar (That holds the game) in there appdata. From there I want the player to be able to run the Jar that they used to download the file and it will bring up a launcher. From the launcher they will be able to press the start game button and it will run the Game or the other Jar in the players appdata. I also want the player to be able to hit a button that will check for an update online and if there is one download the Jar and put it into the players appdata.

A Quick Summary:

  • How do I make a jar that will download another jar
  • How do I make a button that will run another jar
  • How do I make a button that will check for updates and install them

I use net beans to make my softwares!

Thanks For The Help!

No correct solution

OTHER TIPS

the launcher

In your app (the one you distribute) you can simply include a small test routine if a certain jar file is in the folder of your program. If it is there go to the part where you can run the other jar file, if not download it.

Download a file

Have a look at this other SO question on how to download a file via Java. I tested the first answer and it downloads a currencies.csv file. It's only gibberish but it works. The file will be placed in your projects folder.

However the downloaded file will be written line by line into the new file (as Strings, because in this example it is a text file you download). Here is a (very extended) example on how you can read and write a file byte by byte, which may be more appropriate in your case.

running another jar

Now that you have downloaded the new jar file you have to run it. But this may be more complicated, since starting a program (or executing any other command) may be different on every system. However here is another SO question about that. I find the proposal with the Runtime sufficient for my taste but maybe you can find a better way to run the jar.

another proposal

But maybe there is another way and you don't have to download a complete runnable jar file. In other programs such problems are often solved by libraries.

So you could write your game by dividing it into many parts (e.g. each level another jar library). To run your game you would have to posses all the jar files in your lib folder. Your launcher would then first run the routine to detect if all files are present and download the missing jars if necessary.

The multiple-library version might also help you updating your program. That way your players won't have to download the whole game every time a new update is available, but simply the single jar file that changed (you need would need to include a test for that in your launcher, too)

Sorry, if I can't provide any code on that, but it's quite a project you have :) But I hope the links give you an idea on where to start.

You have to use the Java Network Launch Protocol

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top