webnat0
webnat0

Reputation: 2716

how to run in background

I want my Java program to run in the background. How would you do it? Thanks!

Upvotes: 3

Views: 1340

Answers (6)

user7671527
user7671527

Reputation:

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

Upvotes: 0

Jay
Jay

Reputation: 27474

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.

Upvotes: 0

Gerco Dries
Gerco Dries

Reputation: 6712

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.

Upvotes: 2

CoolBeans
CoolBeans

Reputation: 20800

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

Upvotes: 1

ncturn
ncturn

Reputation: 1

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

Upvotes: 0

BalusC
BalusC

Reputation: 1108722

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.

Upvotes: 3

Related Questions