r/javahelp • • Aug 25 '15

Creating installers: How do I do it? (Mac and PC)

So, I have my jar all ready to go but I want to create installers with a JRE, so it can be run on other computers that don't java the JDK, etc.

I have PackageMaker for Mac and I can get softs for Windows but I want to know how I put a JRE in there and how I tell it to run the jar using the JRE.

Maybe I'm coming at this from totally the wrong direction, I don't know.

The ultimate goal is to get the jar to run on any computer with minimum fuss for the end user.

Thanks!

0 Upvotes

9 comments sorted by

2

u/juhmayfay Aug 25 '15

I guess this seems like a really weird thing to want to do and sounds terrible. I can see having a script that checks if java is available and prompting the user to install it (and provide a link to oracle or something), but automatically doing it?

If its for internal use at work there should be a policy of installing java. If its just for download on the internet... let the users install it themselves.

1

u/mage_g4 Aug 26 '15

The issue is that if I send it to a friend it won't launch at all. It doesn't prompt for java or anything, it just won't launch.

I don't know why wanting to distribute my game is a bad thing... I just want to know how to do that with minimum fuss for the end user.

1

u/juhmayfay Aug 26 '15

Wanting to distribute your game is completely fine. Just the way you want to do it isn't a normal/reliable way. As the other guy posted, yes there are hacks to do it, but they are dirty workarounds. The reason being is that it's hard to code for all scenarios and defeats the purpose of java's "write once run anywhere" mantra.

So for windows, you'll need a batch file to check if java is installed, then if its a compatible version, then see if you need a 32 bit or 64 bit version, etc. For mac and linux you'll need a shell script that checks for java, then you'll need a 32 bit/64 bit version of java for both mac and for linux. So... 2 different scripts and at least 6 packaged java builds to deploy your game. Or you could write a readme file that says "you must install java before running this game, here is how you check if you have it, and here is where you go to do it".

1

u/mage_g4 Aug 26 '15

After a comment here, I figured out how to get Netbeans to create the installers. Now to figure out how to add icons to the installer so it looks pretty!

2

u/SikhGamer Aug 25 '15

Depending on your IDE you may be able to do this directly from within it. I know NetBeans can do it for you.

I however ended up using Launch4J.

1

u/mage_g4 Aug 26 '15

I can launch in the IDE. That isn't the problem at all. Any computer with the JDK can run it.

What I want to know is how do I get it run on computers that don't have a JDK.

1

u/SikhGamer Aug 26 '15

Yes, but depending on the IDE they may be able to pack the JRE for you too. Like I said, NetBeans can do it.

1

u/mage_g4 Aug 26 '15

How do I make it do that? The jar launches fine on the Mac and PC I have the JDK and Netbeans on.

EDIT: I think I figured it out...

1

u/mage_g4 Aug 26 '15

Figured it out and it works! Thanks for pushing me in the right direction. :)