• Post Reply Bookmark Topic Watch Topic
  • New Topic

Run a java program when the OS loads  RSS feed

 
mihir maniar
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to run a standalone java code when the operating system loads all by itself just like any other services. i hope the question is clear enough. any kind of help is appreciated. thanks in advance
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What problems are you having in doing that? Under Windows, just put a batch file in the Startup Items folder. Under UNIX/Linux, just run the program from an init script, according to the notmal mechanism for your particular OS.
 
mihir maniar
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.> it works on my machine but not on other machine. it says that there is some error and that command prompt window just goes away. but if i call the batch file seperately, then it works fine.
2.> it is ok for developers machine but if the same has to be deployed on the client's machine then the command prompt window looks ugly and annoying. how to solve this one?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like we're talking about Windows.

Use javaw.exe instead of java.exe if you want to start a program that doesn't open a command prompt.

As far as not working on a customer machine, just check the usual issues: is Java installed? Are the paths right? Is the classpath in the batch file right? etc.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the program starts correctly if manually invoked, java will be installed, and the path will be correct.

You may put a
at the end of the batch-File, to let the user read the errormessage, before using javaw.exe.

Perhaps the path to the jar or class-files is relativ to the location of the bat-file, which is found if the bat-file is called directly, but wrong, when called from the autostart-folder.
 
mihir maniar
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for all the solutions . i worked it out and it is fine. i have put a jar file in the startup folder and restarted windows and java code runs without the comman prompt but the problem is that if i close that window then how should i re invoke the application? i.e. how to re invoke the application from a jar file?
 
Paul Clapham
Sheriff
Posts: 22719
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's in your menu. Click the Start button then select "All Programs" (or whatever your version of Windows calls it) then "Startup" then you will see a link to your jar.
 
mihir maniar
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to ensure that only one instance of that application is running in that case? i mean to say when i click on the jar file in the start menu it will start a new application. i want to start only one instance of this application. how to achieve that?
 
mihir maniar
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for all the solutions . i worked it out and it is fine. i have put a jar file in the startup folder and restarted windows and java code runs without the comman prompt but the problem is that if i close that window then how should i re invoke the application? i.e. how to re invoke the application from a jar file?

this thing is working fine on my machine but on another machine it opens the winrar when the machine starts. this is because in the " open with " property of this jar file winrar program is chosen to open it. i tried to change it to javaw option but no such exe is listed there on another machine. that machine has jre installed and it is the same version as on my machine then what could be the problem. if on that machine when i place the entire path of the jar file in the classpath then it works fine.what is wrong.
 
Paul Clapham
Sheriff
Posts: 22719
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So instead of just putting a link to the jar file in the startup menu (a solution that nobody proposed in this thread), write a batch file that calls "java -jar ..." (a solution that EFH proposed way back at the beginning and that you said thank you for).

As for the "how to have only one instance running" question, I'm sure I have seen that one asked a good number of times. If you searched the forum I am sure you would find it.
 
mihir maniar
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your suggestion Mr Clapham. I would like to know the exact syntax of the "java -jar " solution. secondly there must be a easier way to deploy this code on the client side without having the client to do all this. please suggest some other way if possible. the other machine that i was referring to is that of client.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the "Java in General (Advanced)" forum, and you're asking for the syntax of "java -jar"? That somehow seems odd to me. In any case, try running

java -help

to see information about all sorts of options you may not be familiar with.

As far as your users "having to do all this" -- that's what installer programs are for. Write one.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!