5

I am researching for a project that will involve my project to compile simple enough java files. From my research I have decided not to try and build my own compiler as this would just take too much time.

So does anyone know what would be the best compiler to implement in this project so that I would be able to compile java files that are submitted to the program?

Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
Hip Hip Array
  • 4,665
  • 11
  • 49
  • 80
  • The most obvious solution to this is simply to invoke javac with Runtime.exec. Is there a reason why you can't do this? More information about your situation would help people give better answers. – Nate C-K Apr 19 '12 at 17:05
  • Im really only in the research stage of the project at the moment and trying to find out what the different ways that i could compile .java files from a java program. This is because I am going to build a tool that will compile and grade java programs(for the moment and expand to other programming languages later). It will have alot more features but im just focusing on finding the best way to actually compile the programs first to make sure that they have no errors – Hip Hip Array Apr 19 '12 at 17:10
  • If you plan on expanding to different languages then I definitely think calling the command-line interface to the compiler is the way to go. That way, your program can be expanded to work with any language that has a command-line interface (i.e. nearly all languages). One problem you will face, though, is how to make sure the environment is set up correctly and your program is integrated with the various build tools that may be necessary. (For example, your Java tool may really want to support Ant builds, as students might want to use Ant for more complex projects.) – Nate C-K Apr 19 '12 at 20:24

2 Answers2

9

Why not use the built in Java compiler API ?

Brian Agnew
  • 268,207
  • 37
  • 334
  • 440
0

This almost sounds like you really need a script-y approach that does three things:

  • Compile program source with proper language compiler
  • Execute resulting program to produce some set of results
  • Compare results to expected results to produce a grade

Since you say you want to start with Java, but move to other languages, I would suggest investigating ANT. It will do builds in many languages and can facilitate executing/grading the resulting object code.

Joe Zitzelberger
  • 4,238
  • 2
  • 28
  • 42