To create an online compiler

Asked 1 years ago, Updated 1 years ago, 88 views

Thank you for browsing.
I am currently thinking of creating an online compiler for Java.
In order to create it, I wanted to know how to create it in a modern way.

The online compiler I envision is like the so-called paiza.io,
The program you entered runs on the server side and returns the results.

My implementation image is as follows.

I think 2 is the most likely option, but I would like to do it with a poor server, so if possible, I would like to take 1 method.
I would appreciate it if you could give me some information to help me.

java

2022-09-30 21:49

2 Answers

I don't know much about it, but as far as I've heard...

Lock up your environment with chroot

By the way, there was no Docker for the initial AtCoder's jash server, so I wrote it in full scratch (you controlled it with cgroups, didn't you?), and the current AtCoder is on LXC.


2022-09-30 21:49

A few years ago, I created a system to compile and test the code that users entered in textarea and so on on the server side.

I don't know if it's modern or not, but I usually did it as follows.

Compiling

  • Save the user input code to a file so that the compiler can read and write using StandardJavaFileManager (it would be nice to implement the interface above and do it all on-memory, but I made it a file with the policy below.)
  • Get the compiler from javax.tools.ToolProvider.getSystemJavaCompiler()
  • JavaCompiler.CompilationTask compilation=compiler.getTask(...)
  • compilation.call() prints the class file to the location you set in fileManager earlier (compilation errors can be caught as Java exceptions)

When to Run

  • Create a java policy file to restrict files and network access (Note https://docs.oracle.com/javase/jp/7/technotes/guides/security/PolicyFiles.html)
  • javaSpecify -Djava.security.policy= (policy file path) as the argument for the command
  • If you want to be variable in the policy file, such as the location of the user code, refer to the system properties in the policy file, and pass the value to the argument of the java command like -Dsome.property.key=hoge.

I hope it will be helpful.


2022-09-30 21:49

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.