I want to be able to call javac <class file name>, and then automatically run java on the compiled .class file.

I thought initially to use a x86 disassembler to hack it (javac.exe) but bumped that idea; I then found the open source code for JDK, and concluded that maybe a batch file would be easier. How can I do this?

closed as off-topic by user40980, Kilian Foth, Bart van Ingen Schenau, World Engineer Mar 13 '14 at 13:19

  • This question does not appear to be about software engineering within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 2
    Batch file sounds good to me. What are you trying to achieve? – Shivan Dragon Sep 6 '12 at 21:28
  • consider studying tutorials on Java CLI and javac cmd line usage. Also, there are plenty tools that do stuff like that - just search web for stuff like Ant, Maven, Ivy, Gradle etc etc etc – gnat Sep 8 '12 at 9:33
  • Also note that for most non-trivial projects the class you compile is most likely not the one you want to run. – user1249 Sep 8 '12 at 10:02
  • 3
    This question appears to be off-topic because it is about an implementation/tool issue but is too old to migrate to Stack Overflow. – user40980 Mar 12 '14 at 20:22

It would probably be easier to use a build tool, like Ant. You could have a target to compile, a target to run your tests, a target to run, and so forth. You can set up different dependencies between them (for example, always make test clean your build files and compile before running).

Alternatively, a shell script would be the next best bet. However, that would be far less portable than something like Ant.


Do you want to run this as a process from within another Java process or from the Shell ?

If its from within a Java process,take a look at the Processbuilder API

  • I really appreciate and comend your help, but I think I will just use an IDE... I had to just use the command line for a lab for school. I don't HAVE to use it from the command line after using it to get the feel for it. Thanks however. – Chris Okyen Sep 6 '12 at 23:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.