Edit: the answer below works on Linux, not Windows. It's probably not what you need, but since I wrote it already without noticing that it's a Windows question, I'll leave it for the sake of potential future readers.
This is how it can be done on Linux:
I guess you could write a bash script and run it as a service.
I'm using the
daemon package to do this. Here is an example recipe you can start with:
# the package that lets you easily define new services
# script file used by service to launch your java program
file "/my/path/run_script.cmd" do
content "java --flag1 --flag2 -jar /my/program.jar\n"
# setup the service (based on the script above),
# start it, and make it start at boot
cookbook_file '/etc/init.d/myservice' do
service "myservice" do
supports :restart => true, :start => true, :stop => true, :reload => true
Note that you'll need to add a file named
etc_initd_myservice to your cookbook. You can use the content in this answer as basis for this file. This is the file that employs the "daemon" package to run a script as a service.
Also, the following question might contain relevant information if you're having problems with defining a service and creating its init.d script in the same recipe.