Create java IDE

Hi all

Is there a way to run a java code that was received to the server using ajax call from html. need to create an ide

It is preferable to run without creating any files

Yes, but thats much harder than to do it with python, since Java needs to get compiled and enforces a certain layout of how files have to be organized.

My suggestion to not run arbitrary user supplied code does still hold.

Also I am not sure why you actually want to run arbitrary code written in language X for an IDE. Personally I do use IDEs to write, edit, view, and compile code. Not to run it. Perhaps I’d like to run tests, but therefore you usually do not run a sourcefile but rather a wrapping testrunner, which compiles, runs and formats the output.

Well, our aim is to take java code as input from the user. Then, compile and run the code and send back to the user the output of the program.

How do you think I should run the java file at the server?

If you do not seal up the running system correctly your user can access arbitrary files, get access to environment variables, etc.

Therefore I do assume, that at least running the compiled program will happen in a sandboxed environment.

  • Compile the file using javac. javac is not able to read from stdin, you will need to write out the file and run javac from a working directory relative to the file that fits Javas requirements of how to discover packages.
  • use jar to create a package from the created *.class files.
  • Transfer created *.jar to sandbox
  • run it using java -jar

If you have no clue how to properly sandbox the execution, do not offer this as a service or ask for professional help! You can get into serious trouble if done wrong (or not at all)!

Is there any way we can compile the java file without doing “javac File.java”. As far as I know there is no other way.

Also, I was able to send a json file to exec.Command(“python”, params.Get(“JSON FILE”)) and it worked perfectly. If there is a way to run java code without creating additional files, my work is easily done. Please let me know if there is a way to do that.

As I said earlier, the java compiler needs a file, which has to be placed at a certain location relative to javacs working dir. You can not get around that limitation without writing your own java-compiler.

Also calling python with a JSON file makes absolutely no sense. The command you have shown, will run python and tell it to run the file that has the name as whatever gets returned by params.Get("JSON FILE"). If the returned value is in fact a stringified JSON-object, I doubt that you have a file which is named exactly like that.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.