Preparation

  • copy student source codes to a directory where each subdirectory contains the source code of a single student
  • a valid directory containing student solutions might look like this:
            solution_directory
            |- student1
               |- classA.java
               |- ...
            |- student2
               |- ...
            |_ student3
               |- ...
    

Usage

Download the JAR and include it into your Java project. Alternatively use Maven (note: there is no public Maven repo including MOJI as of writing this).

Example code

You can find a preconfigured Eclipse project in the "example" subdirectory. This is the relevant snippet from it:

        import java.io.File;
        import java.util.Collection;
        import java.net.URL;
        import org.apache.commons.io.FileUtils;
        import it.zielke.moji.SocketClient;
        
        public class QuickStart {
                public static void main(String[] args) throws Exception {
                        // a list of students' source code files located in the prepared
                        // directory.
                        Collection<File> files = FileUtils.listFiles(new File(
                                "C:\\temp\\solution_directory"), new String[] { "java" }, true);

                        // a list of base files that was given to the students for this
                        // assignment.
                        Collection<File> baseFiles = FileUtils.listFiles(new File(
                                "C:\\temp\\base_directory"), new String[] { "java" }, true);
                        
                        //get a new socket client to communicate with the MOSS server
                        //and set its parameters.
                        SocketClient socketClient = new SocketClient();
                        
                        //set your MOSS user ID
                        socketClient.setUserID("123456789");
                        //socketClient.setOpt...
                        
                        //set the programming language of all student source codes
                        socketClient.setLanguage("java");
                        
                        //initialize connection and send parameters
                        socketClient.run();
                        
                        // upload all base files
                        for (File f : baseFiles) {
                                socketClient.uploadBaseFile(f);
                        }
                        
                        //upload all source files of students
                        for (File f : files) {
                                socketClient.uploadFile(f);
                        }
                        
                        //finished uploading, tell server to check files
                        socketClient.sendQuery();
                        
                        //get URL with MOSS results and do something with it
                        URL results = socketClient.getResultURL();
                        System.out.println("Results available at " + results.toString());
                }
        }