Docker-based java compiler API server
- Required Docker
# download and run kykungz/compilr-java image (port 8080)
docker run -it -p 8080:8080 --name compilr-java kykungz/compilr-java
# clone the repository
git clone https://github.com/kykungz/compilr-java.git && cd compilr-java
# -----edit config.js file-----
# build an image
docker build -t kykungz/compilr-java .
# run kykungz/compilr-java image (port 8080)
docker run -it -p 8080:8080 --name compilr-java kykungz/compilr-java
With this installation, you can configure the environment by editing config.js
file before building an image. See Configuration
below.
After running the script above, you can now access your container using command:
# open current tty
docker attach compilr-java
# OR
# open new tty
docker exec -it compilr-java bash
Compilr will create a simple API server on port 8080 by default. You can compile and run your code by sending a HTTP POST
request to your https://localhost:8080/compile route, with a JSON request body similar to:
{ "files": [
{
"name": <class_name>,
"content": <source_code>
},
{
"name": <class_name>,
"content": <source_code>
}
] }
Example:
{ "files": [
{
"name": "Run",
"content": "public class Run {public static void main(String[] arg) {System.out.println(Hello World!);}}"
}
] }
The response will be in JSON format with structure:
{
"success": <boolean>,
"output": <runnig_result>
}
Example:
{
"success": true,
"output": "hello world!10\n"
}
If there is a compile/run error, success field will be false
and the error output will be shown.
compilr also provide a simple code editor frontend on your https://localhost:8080
config.js
Key | Detail |
---|---|
TIMEOUT | Terminal cpu time limit (in seconds) |
LOG | Logging (boolean) |