# Add New Language
Choose an appropriate Docker image, write test code files, and build a custom Dockerfile that contains at least the following:
Why Code for test needed?Refer to How To Be Safe? #3
FROM xx:version # Base Image # Follow 3 steps are necessary WORKDIR /code COPY test.xx . RUN mkdir languageName # eg.py/java/c CMD ["bash"]
Configuration:
Config config = new Config(ModeEnum.CLASSIC) .addLang(languageName,languageFileName,imageName,testCommand,testResult) ...
Among them:
Parameter Name Meaning languageName languageName in 1st step, as the first parameter of runCode
method.languageFileName The code file name created, requires special attention to the main class name problem for Java
language.imageName Image Name built in 1st step. testCommand Commands for test. testResult Expected results of the test for normal execution.
# Example:DJudger Default C++ Configuration
https://github.com/NicerWang/DJudger/tree/master/containers/c
File Preparation:
Dockerfile
FROM gcc:9.4 WORKDIR /code COPY test.cpp . RUN mkdir c # must be identical with languageName CMD ["bash"]
Code for test
#include<iostream> using namespace std; int main(){ cout<<"Pass"<<endl; }
Build Image:
cd containers/c sudo docker build -t judger_c .
Configuration:
Config config = new Config(ModeEnum.CLASSIC) .addLang("c","main.cpp","judger_c","g++ test.cpp&&./a.out","Pass") ...