How to package my Text Game

I developed a text adventure game played in the console for an english project. I need to export it to a jar or an exe so a layman like my teacher can play it. I tried exporting it and it either does nothing or throws up an error warning that says “Could not find main class GameStarter.class” Can you guys help me out?

If you are using eclipse, you need to export it as a runnable jar. File --> Export

However, simply double clicking this jar won’t open it since it’s supposed to be in the command prompt. You need to open notepad and write this line of code in there:

java -jar “JAR NAME HERE”.jar

Save that as “Play.bat” Make sure it is a batch file!

Then just put it into a zip or rar archive, and send it to him. Tell him to run the batch file to play the game. (note the .bat and .jar files have to be in the exact same directory)

Hope this helps.
-Nathan

Thanks! This is exactly the kind of answer I needed.

No problem 8)

Thank you both, you have answered an old question I had for some time now.

Cheers! :slight_smile:

Edit:

Well, I have some doubts left:

What happens when exporting a large project with many resources, like 20 classes (20 .class files), textures, libraries… It all comes to ONE .jar? And that’s the “game”? Double clicking it runs it? (not a text game like OP)

If it’s more complicated, but not using .dll style libraries, then yes that’s all.

I’ve got several projects that are LOTS of classes. By that, I think it’s… 50-60 classes? Perhaps more. I’m not sure off the top of my head, and it works through one jar. Only issues are making sure that people remember to pick up the outside config classes and the like.

Only when you’re using native libraries, or libraries with license separate packaging requirements, will you have to do it another way. There are other situations where it might be best to do it another way as well. As I understand it, linux likes to treat .jars differently, certain installed software will cause it as well (Since in essence, a .jar is just a packaging/compression file like a .zip, .rar, .7zip, etc).

To calm your doubts of using many classes in one jar, Minecraft uses HUNDREDS of classes, and it is only one main jar, plus the external libraries and stuff. ;D

-Nathan

Sure, I know that :wink:
What I don’t, it’s relative to the topic, how to wrap all those things together and make a poolish distribution version of the game, maybe an installer? maybe a stand alone?

Thanks for your reply :slight_smile:

Minecraft is tiny. I regularly package enterprise apps that use Spring and such into one jar, and it adds up to thousands of classes. If this ever threatens to get slow, the jar format supports an index file to speed things up. You are never going to overstuff a jar in any normal use.

There are a lot of single jar packers, including JarSplice, written by our own Kappa. My personal favorite is One-JAR, which uses nested jars (makes it easy to add and remove entire jars using the ‘jar’ command alone) and has its own simple solution to the native libs problem of using a binlib/ directory you just drop things into. It also integrates nicely into ant, maven, and sbt builds.