JAR installer that auto-detects if Java is there and autostarts the application

帅比萌擦擦* 提交于 2019-12-29 06:25:09

问题


I need to build an installer that does the following:

  1. Installs my jar on the client.
  2. Auto-detects if JRE is installed (in which case it does not re-install it), otherwise installs it without the user clicking on another button.
  3. Auto-starts the application when the client is booted.
  4. Works across Windows, Mac and Linux.

Any idea how to go about it?


回答1:


If a commercial tool is ok, I can recommend install4j. 1, 2 and 4 are easy to do with it, but about 3 I'm not sure. Edit: You could probably achieve that by installing your app as a "service", which install4j supports for all platforms. Quoting from its Features page:

install4j offers full support for generating and installing services (daemons). For services, install4j generates service executables on Windows, startup items on Mac OS X and start/stop scripts on Unix/Linux platforms.

Edit: Regarding #2, JRE detection: install4 has pretty nice, flexible options for JRE bundling/detecting. You can include a JRE (statically or dynamically, shared or not) or prefer to use one already present, with the possibility to download a JRE from within your installer as a fallback. Check these docs for more: How Installers Find a JRE and JRE Bundles.

(More about my experiences with install4j.)

For other tools, you could check some of the earlier Java installer questions on SO:

  • What’s the best way to distribute Java applications?
  • Java Application Installers
  • What is the best installation tool for java?



回答2:


Commercial tools like InstallAnywhere can do that. After installing the JAR (and links and such), installers can check the registry if Java is already installed and proceed or not. As long as the installer supports all needed plattforms, you are fine.




回答3:


You could use launch4j , it does not automatically install java however. But maybe there's a way to make that work by packaging the JRE for example.




回答4:


You may also want to take a look at BitRock InstallBuilder, it provides built-in functionality to perform what you want. We will be happy to build a sample installer for you, just drop us a line.




回答5:


I recommend downloading the source code for the build scripts of popular Java programs like limewire and follow their example. The end.

...Or you can do like I did:

  • I have done the JRE detection and download/install of redistributable if required with NSIS on Windows. Maybe an .msi is better than a installer.exe which NSIS creates. I believe msi are more like packages on mac so they allow proper updates. Maybe NSIS creates MSIs... not sure.
  • Mac is simply an Java App bundle and you specify the JRE and other Java info in the info.plist and you can optionally create a .pkg file to give the user an installer and bundle up in a dmg using the command line dmg programs.
  • I haven't done Linux and don't plan to... sorry :)

All this was a fair chunk of work. I first did the Windows stuff then a couple years later did the Mac stuff.

You can integrate all of this in NSIS build scripts and Ant. I can't remember why I didn't use install4j. Probably I was too cheap :)




回答6:


Haven't heard of anything that works across all those platforms, but JSmooth might help (fits your needs on Windows). I've used it about 2 years ago and it worked fine.



来源:https://stackoverflow.com/questions/995881/jar-installer-that-auto-detects-if-java-is-there-and-autostarts-the-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!