tags:

views:

64

answers:

3

Hi guys.

Does enyone know if it is possible to launch a java application in Eclipse but in a loop. I need to execute a application all the night. If I try tu run it in win console, it is complicated, I have ti specify a bunch a parameters.

Thanks alot.

Regards, Corneliu.

+3  A: 

Just run the way you would run a regular Java program, in a loop:

public class MyProgram {
   public static void main(String[] args) {
       // your infite, of finite loop goes here
   }
}

And then, just run it, and if there are not unhandled exceptions, it will run all night indeed.

Pablo Santa Cruz
Wow, it was so simple. I did't saw it. Thanks.
CC
If this answer is acceptable to you, please hit the checkmark to accept it so the answerer will get some reputation points. Welcome to StackOverflow!
MattGrommes
Actually, it does not work for me.There a system.exit somewhere in the code. If I remove it, is not good because it is there for a reason, because we work with many threads.Any ideas to overcome this ?
CC
Can you post some of the code you are referring to?
Pablo Santa Cruz
+1  A: 

Eclipse is a development environment, not an application manager. It's not well suited for what you're asking to do. It might be best to learn what those parameters are and why you need them, and write a batch file to handle them for you. There might be a better answer if you provide more details.

Jonathon
eclipse is so much more then just a simple, stupid IDE ;)
Andreas_D
I love Eclipse -- it's very flexible and it's not simple nor stupid. But if you need a hammer, a screwdriver won't do you much good. Of course you can pound on something with the handle of a screwdriver, but it's the wrong tool.
Jonathon
Agreed, round peg, square hole.
Michael Krauklis
+2  A: 

Wrap your main in a call to Runtime.exec and put that in a loop.

public static void main(String args[]){
     while(true){
          Process proc = Runtime.getRuntime().exec("java yourclasshere");
          try{
               proc.waitFor();
          } catch (InterruptedException e) {}
     }
}
Michael Krauklis
Yes - this should survive the System.exit() calls :)
Andreas_D
How is this superior to writing a quick batch file that does the same thing? Why would I want to go to the trouble of writing a Java program to manage my application? This isn't rhetorical, I'm honestly interested in why you would do this.
Jonathon
I was making two assumptions: first, that since they wanted this to be run in eclipse they wanted it to be a java solution; two, that Corneliu C might be more comfortable in a java environment. I completely agree, it's going to be simpler to just write a quick script rather than something that needs to be compiled, but given my assumptions this seemed to fit better.
Michael Krauklis