Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for a "bootstrap" script to be run before application start #122

Closed
2 of 5 tasks
keastrid opened this issue Aug 8, 2021 · 15 comments
Closed
2 of 5 tasks

Allow for a "bootstrap" script to be run before application start #122

keastrid opened this issue Aug 8, 2021 · 15 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@keastrid
Copy link
Contributor

keastrid commented Aug 8, 2021

I'm submitting a…

  • bug report
  • feature request
  • other

Short description of the issue/suggestion:
The ability to run a script before launching the application's java runtime.

What is the motivation / use case for changing the behavior?
When an application has its own update facility, it is useful especially in long lifetime applications to allow for the bundled jre to be updated, either on user demand or part of its normal update process, without forcing users to entirely reinstall the application. At least on windows, you cannot update the jvm while it is running, forcing the use of an "elevator" process, written as a shell script or some other application, to update it.

Rather than starting a new process on a timer to rename the folders (eg. jre -> jre.old, jre.new -> jre) and immediately shutting down the program, it would be more useful to have a script capable of doing so on program startup, hence a bootstrap script.

I imagine others may have more uses for this feature.

Please tell us about your environment:

  • JavaPackager version: 1.6.0
  • OS version: Windows
  • JDK version: 16
  • Build tool:
    • Maven
    • Gradle

Other information (e.g. related issues, suggestions how to fix, links for us to have context)

@fvarrui fvarrui added the enhancement New feature or request label Aug 10, 2021
@fvarrui
Copy link
Owner

fvarrui commented Aug 11, 2021

Hi @keastrid!

I've been thinking about this. On Mac and Linux I think it's relatively easy to implement the execution of a script at startup, since we use our own scripts to start the application. But it isn't like that in the case of Windows, where we have a binary generated with launch4j, and it doesn't have an option that allows us to execute anything at the beginning. Any suggestions? Maybe a batch file (converted to EXE and edited to have an icon and other metadata attached) which launch the bootstrap script and then the binary.

Rather than starting a new process on a timer to rename the folders (eg. jre -> jre.old, jre.new -> jre) and immediately shutting down the program, it would be more useful to have a script capable of doing so on program startup, hence a bootstrap script.

Why do you think that this is not a good alternative?

@fvarrui fvarrui added the help wanted Extra attention is needed label Aug 11, 2021
@keastrid
Copy link
Contributor Author

I don't think its a good alternative as, in my case of a jre updater, it essentially requires download -> unpack -> start timer immediately and shutdown, or wait for user confirmation and do the timer and shutdown. It is also easier to get the application into a bad state, as the process could be killed while it is running leaving the application seemingly unusable from a user perspective.

A startup script that can do so can more easily inspect the state of the working directory and determine how it should rename things, so it can recover from a failed move/rename by automatically reverting to the backup.

@fvarrui
Copy link
Owner

fvarrui commented Aug 21, 2021

Work in progress in branch issue-122.

@fvarrui
Copy link
Owner

fvarrui commented Aug 23, 2021

I've just implemented and tested this feature for Mac OS, and it seems to work fine.

you have to use scripts.bootstrap property:

scripts {
    bootstrap = file('path/to/your/bootstrap.sh')
}

The specified bootstrap script is copied to Contents/Resources/scripts folder with execute permissions and run just before the app.

@fvarrui
Copy link
Owner

fvarrui commented Aug 23, 2021

Also works on Linux!

@fvarrui
Copy link
Owner

fvarrui commented Aug 23, 2021

I don't know how to implement this feature for Windows. Any suggestions would be welcome!

I think we need a separate EXE from the JVM, which has to be executed from the application, or use a BAT file as startup.

This is how Google Chrome does it.

@keastrid
Copy link
Contributor Author

A separate exe may be the better option, as things like IntelliJ software and Chrome use exes rather than scripts.

@fvarrui
Copy link
Owner

fvarrui commented Aug 31, 2021

I managed to run a startup script on Windows. For this we need a VBS script and a shortcut pointing to it. The VBS script runs the bootstrap script and finally runs the binary. Shortcut can be configured with an icon. Installers also generate shortcuts pointing to the VBS script file.

@fvarrui
Copy link
Owner

fvarrui commented Sep 2, 2021

Please, try this feature for all platforms as soon as you can, so I can release v1.6.0 to Maven Central. Thanks!!

@keastrid
Copy link
Contributor Author

keastrid commented Sep 4, 2021

Thanks!
Tested with your HelloWorldGradle project.
Windows and linux work. On mac the app can't be opened - it may be a permissions issue as I'm building it on windows. I will need to test further.

@fvarrui
Copy link
Owner

fvarrui commented Sep 4, 2021

Shortcuts must be generated by installers, as it's not possible to make them reference to relative paths, so It has no sense to package a pre-built shortcut with the app

@fvarrui
Copy link
Owner

fvarrui commented Sep 6, 2021

On mac the app can't be opened - it may be a permissions issue as I'm building it on windows. I will need to test further.

There was a bug that I just fixed.
Thanks!

@fvarrui
Copy link
Owner

fvarrui commented Sep 6, 2021

The problem was that the bootstrap script execute permissions were not set when packaging as tarball/zipball

@hectorqin
Copy link

I think it's time to release v1.6.0!

@fvarrui
Copy link
Owner

fvarrui commented Sep 10, 2021

JavaPackager v1.6.0 released to Maven Central

@fvarrui fvarrui closed this as completed Sep 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants