开发者

how to run in background

I want my Java progra开发者_JAVA百科m to run in the background. How would you do it? Thanks!


That's not to be decided by the Java program, but by the operating system and the enduser. The enduser has just to configure the operating system so that it get executed during startup or as a scheduled task.

You just have to make sure that your program doesn't spawn any UI or so.


I have often used Tanukisoftware's Java Service Wrapper for this exact purpose. It allows you to create a Windows Service for any Java application and it can run in the background, start with the OS, etc.

The "Community Edition" does what you need and is completely free to boot.


If it was Linux I would have said just execute the java app as a background job. Something like

nohup java your_app &

...

Although I have not used this in windows but by googling I found that start /b command does the same thing. Perhaps you could try something like this:

start /b java your_app


Have you tried making a Swing GUI application and setting setVisible(false)?


What's your definition of "running in the background"? By default, a Java app does not have a console. So if you don't create a window in main, it will have no visible UI. I would think that would qualify as a background job.


to run .java in background use

java FileName &

to run .jar in background use

java -jar FileName.jar &

Please use & at the end to run in background

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜