Online code compilation and execution engine — supports Java and Python. Originally extracted from the codessp online teaching platform.
- Java online compilation — Uses JDK Compiler API (
javax.tools) to compile user code in memory, then executes via subprocess - Python online execution — Writes code to a temp
.pyfile and runs via Python subprocess - Process timeout protection — Detects infinite loops (2 min output timeout / 500-char output buffer), kills processes automatically
- Chinese error messages — Maps Python/Java compile errors to human-readable Chinese descriptions
- Interactive input — Supports code that uses
input()via SSE +/processInputendpoint - SSE real-time output — Streams output to the frontend as it's produced
- Execution history — Optional JPA persistence for every run (
OnlineCodeentity)
- Java 17
- Spring Boot 2.7.18
- JPA / H2 (default, MySQL optional)
- Maven
# Build
mvn clean package -DskipTests
# Run
java -jar target/code-runner.jarDefault port is 8088. Test endpoints:
# Execute Python
curl -X POST "http://localhost:8088/exec" -d "code=print('hello')" -d "codeLang=python"
# Execute Java
curl -X POST "http://localhost:8088/exec" -d "code=System.out.println(\"hello\");" -d "codeLang=java"| Method | Path | Description |
|---|---|---|
| POST | /exec |
Quick execution — blocks until result is ready |
| POST | /runCode |
Run code, use GET /output for real-time output |
| GET | /output |
SSE real-time output stream |
| POST | /processInput |
Send input to a waiting process |
All settings in application.properties:
| Key | Default | Description |
|---|---|---|
coderunner.java.compile-temp-path |
(system temp) | Java class output directory |
coderunner.python.command |
python |
Python interpreter command |
coderunner.temp-dir |
(system temp) | Python temp script directory |
codeRunner/
├── pom.xml
├── README.md
└── src/main/java/cn/coderunner/
├── Application.java # Spring Boot entry point
├── code/ # Core compile & execute module
│ ├── CodeCompile.java # Abstract base — output & error handling
│ ├── CodeRunner.java # Runtime manager — threads, timeout, error mapping
│ ├── JavaCompile.java # Java online compiler
│ ├── PythonCompile.java # Python executor
│ ├── JavaSourceFromString.java # In-memory Java source file
│ ├── SimpleProcess.java # Process PID tracker
│ ├── ProcessInput.java # Process stdin writer
│ └── ProcessOutput.java # Process stdout reader
├── controller/
│ └── ExecuteCodeController.java # REST controller
├── entity/
│ └── OnlineCode.java # Execution record JPA entity
├── repository/
│ └── OnlineCodeRepository.java # JPA repository
└── util/
├── Common.java # Utility methods
└── DeleteFileUtil.java # File deletion utility
| Change | Description |
|---|---|
| Package | cn.jssp.* → cn.coderunner.* |
| Hardcoded schema | Removed schema = "javaidc_jssp" |
| Controller | Removed BaseRestController, uses @Autowired HttpServletRequest/Response |
| Response model | Replaced CommonMessage with standard ResponseEntity<Map<String, Object>> |
| CodeRunner deps | OnlineCodeRepository is now optional (via Consumer<OnlineCode> callback) |
| File deletion | Uses java.nio.file.Files instead of Java 1.x File.delete() |
| Hardcoded paths | PythonCompile.COMPILE_TEMP_PATH_2/3 etc. → configurable, default to system temp |
| Removed | JavaCompile2, JavaCompileTrandition, JavaRunnerTradition, PythonRunnerTradition, MultipleJavaCompile |
MIT