• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

automatically compiling a java program

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i am experimenting with a java program that automatically recompiles and runs another program if it is modified.if the other program is not modified then my program will simply run it. i am running this on a windows 2000 machine. I am using File object for checking if the source code of the program is modified. if it is modified then a Runtime instance will call the java.exe or javac.exe as the need maybe. Please tell me what arguments i have to pass to the runtime instance.thanks in advance.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should be exactly what you'd type in a command window to run the program or do the compile manually. If you have to do two or three commands - like setting up path and classpath before running java or javac - consider putting the tricky bits in a batch file and launching that from your runtime.exec().
 
shankar surendranath
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i tried it with runtime instance.here is the code.runtime is an instance of the Runtime.
// compiling the program
runtime.exec("javac Myprogram.java");
// running the program
runtime.exec("java Myprogram.java");
But it doesnt work.can you suggest a solution for this?
 
Stan James
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If nothing else, this will likely fail because the java command launches before the javac command is done. When you run a command you get back a Process object. Look at the Process API for a way to wait for it to finish and check the return code before launching the next one.
You can also get the stdout and errout streams from the process and read them to see what's going on. These should help you figure out just what's going wrong. You might display the output on the screen, or scan it for interesting success or failure messages from the compile. If you are reading these two streams until you get an EOF (-1) byte I think you can skip the waitFor() call, because the streams usually end (in my limited tests) long after the waitFor() returns.
As another approach, you might exec a batch file which runs javac and java and redirects the outputs to files. Then you can read the files manually to see what's going wrong. Hope that helps!
 
reply
    Bookmark Topic Watch Topic
  • New Topic