File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Making a command-line app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Making a command-line app "keep going"" Watch "Making a command-line app "keep going"" New topic
Author

Making a command-line app "keep going"

Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Is there an accepted coding idiom for having your java application follow this scenario?

I start the program with a shell script or batch file, and the script will complete and exit, but the program is actually still running.

Something like the Tomcat startup scripts.

The second part of the question is... is there an idiom for the 'shutdown' half of this equation (that is relatively simple to implement)? I think the Tomcat shutdown script uses the fact that the Tomcat executable listens on a certain secret ( but known ) port for a 'shutdown signal'.

Is this the best way to do this sort of thing?
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Sourceforge has a Java Daemon Launcher that you might want to look at.
[ May 22, 2003: Message edited by: Cindy Glass ]

"JavaRanch, where the deer and the Certified play" - David O'Meara
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

I'm dragging this up again, because it's on my radar at work again.

Basically, I'm using the Quartz package to provide a server-wide scheduling service. It's basically cron, only accessible from java applications through a very nice API.

The problem is that I have written a small 'launcher' class that will start my scheduler, but when this class is forcefully 'terminated' (in Unix, by ctrl-C'ing the XWindow), then my scheduler goes away.

So the answer would seem to be using some OS-level script trickery. like using nohup and the & to get my prompt back.

And then I ran across this (old) JSR: http://www.jcp.org/en/jsr/detail?id=96

The gap they refer to? I'm in it.

That sf project doesn't even have code yet Cindy. I'm thinking I'll just have to go the OS route and write clever little scripts that make use of pids and what not.

I shoulda stayed awake in sysadmin class. Oh wait.. I didn't have any of those, I'm a programmer!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making a command-line app "keep going"