简体   繁体   中英

how to run in background

I want my Java program 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

您是否尝试过制作Swing GUI应用程序并设置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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM