• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to run jar file when computer is off?  RSS feed

 
Glenn Jayasuriya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I finished my program.
It runs when I run it on eclipse.
But when I close eclipse it stops.
So I exported it to a jar file.
Now with eclipse closed I can just double click the jar file and it will run.
What I'd like to do is somehow have my program running even when my main computer is off.
I've never done this before and I don't know the basics.
Someone said I can use my raspberry pi or some other low power computer to run the jar file 24/7.
Is there a better way than that?
Thanks you!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can of course not run any program on a computer that is turned off... just like you cannot drive a car, or use any electrical device, that is not powered on.

You'll need some kind of computer, it could be a Raspberry Pi, that is turned on.
 
John Joe
Ranch Hand
Posts: 434
3
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to run jar file when computer is off?

If you are creating batch service, than you can.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12563
49
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Joe wrote:
How to run jar file when computer is off?

If you are creating batch service, than you can.

If the entire computer is powered down, how exactly would this work? 

As Jesper said, there must be something powered up for the file to run. It could be a desktop, a phone, a raspberry pi, or some other piece of equipment, but something has to be on.
 
Junilu Lacar
Sheriff
Posts: 11486
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is why you need to be very precise when you talk to computer people. We take things very literally. When I saw that subject line, I literally LOL'd at how ridiculous it sounded and my reasoning was exactly as Jesper expressed. That's like asking "How do I run when I'm dead?" Well, dead men can't do anything but lay there, right?

I think I know what you mean though.  Search for "nohup"
 
Glenn Jayasuriya
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason why I ask this because I wondered if you could get a domain or some other online service to host the file for you.
So while my machine might turn off, some other machine might run it for me.
Also can you elaborate on the nohup?
I've run programs on unix with nohup on my linux machine. When I close terminal, (exit out of unix) the program stops.
I guess there is some sort of command that allows you to run the program in the background but the machine has to still be on.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, nohup is a way to keep a program running on Unix-like operating systems (such as Linux) when you close the terminal window. It will not allow you to run software when the computer is off.

There are online hosting services for people who run websites or web applications. They have servers somewhere in a data center, and you can run your website on these servers. Depending on the offering, the environment has more or less restrictions. If you want access to a (virtual) server, where you can run anything you like, then you can look at VPS (Virtual Private Server), which will probably be more expensive than just hosting a website. You could find Internet hosting providers and see what they offer.

You can also run software in the cloud. The big Internet companies, such as Amazon, Google and Microsoft, have thousands and thousands of servers all around the world. You can get an account from one of them and use these servers. With for example Amazon you get limited access for free. You'd have to do some research to find out exactly what you would need and how it works exactly.
 
Junilu Lacar
Sheriff
Posts: 11486
180
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@Glenn, you keep saying "keep the program running when the machine is off." Either you are not expressing yourself correctly or you have a fundamental misunderstanding of how the kind of program you are thinking about works. Nothing, I mean NOTHING, can run on a machine that is not powered on. You can open up a terminal on your computer, connect to a remote machine, start a process on the remote machine, put that process in the background with nohup, then disconnect from the remote machine. You can then turn off your computer. The process you started on the remote machine will continue to run as long as nothing happens that causes it to terminate. One cause for termination is when the power on the remote machine is turned off.

If you want to know more about nohup, go out on the Internet and research it. The basics: it means NO HangUP and nohup is used to prevent a process from being stopped when the connection from which it was started is terminated by logging out.
 
Carey Brown
Saloon Keeper
Posts: 3317
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When you look for someplace to host your Java programs double check with the provider, mine for instance, only allows PHP programs to run, no Java.

Anybody know if there's a NAS box that can run Java? I have a QNAP box that it might be interesting to run some Java on but I haven't run across any mention of running Java on it. Even if you could, how would you access it remotely? ... (all sorts of questions)
 
Ron McLeod
Bartender
Posts: 1602
232
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As others have mentioned, AWS for cloud hosted, and Respberry Pi for locally hosted are both good solutions.

After the 12 free months with AWS, you could expect to pay around $4.50 per month for 24x7 operation for the smallest instance -  a t2.nano.  That type of instance gives you 512MB of RAM, 1 vCPU (equivalent to a 2.4GHz i5, continuous usage at 5%, burstable to 100%), GBs of storage, and a public IP address.  The instance would most likely be running AWS's Linux distribution.

For around $40, you can get a Raspberry Pi 3 with 1GB RAM, 4 CPU cores running at 1.2GHz, and whatever amount of storage you want to give it using an SD card.  There is a large variety of operating systems including various flavours of Linux, Android, and Windows 10 IoT version.  I've had lots of success running Java applications using the Raspbian (Debian) distro.

Raspberry Pi also gives you access to 20 lines GPIO (which you can control from your Java app), allowing you to interface with switches, sensors, LEDs, buzzers, relays, etc., which might be useful depending on your application.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!