Skip to content
VirtualLP Virtual Learning Platform

Practical 4: Installation of CloudSim Environment

15 min read Topic 13 of 31 1 hands-on lab

Aim

Set up the Java JDK (Java Development Kit) and Eclipse. Add the CloudSim libraries to a Java project. Run the sample program and check its result table.

Theory

CloudSim is a Java library for simulating clouds. A library gives your program ready-made classes to use. CloudSim does not create real servers.

Its libraries come in JAR (Java Archive) files. Add these files to the project's classpath, the list of places Java searches for classes. Your program can then use classes such as Datacenter, Vm and Cloudlet.

recipe book

A JAR is like a recipe book of ready-made code. Installing CloudSim is not like installing an app – it is like putting the recipe book on your kitchen shelf (the classpath) so your cooking (your program) can use its recipes. The JDK is the kitchen itself (stove = compiler, plates = runtime), and Eclipse is a well-organised kitchen counter.

Component Why it is needed
JDK (Java Development Kit) Compiler (javac) and runtime (java). CloudSim 3.0.3 works with Java 8 and newer. A JRE (Java Runtime Environment) alone cannot compile code.
Eclipse IDE (Integrated Development Environment) for Java Developers Editor, compiler integration, build-path management and console.
cloudsim-3.0.3.jar The CloudSim classes.
cloudsim-examples-3.0.3.jar Ready-made example programs (CloudSimExample1 … 8, network and power examples).
commons-math3-3.6.1.jar Apache Commons Math – required by CloudSim’s statistical/power classes.
flowchart LR
    JDK[Install JDK<br/>set JAVA_HOME + PATH] --> EC[Install Eclipse] --> DL[Download & extract<br/>cloudsim-3.0.3.zip<br/>commons-math3] --> PR[Create Java project<br/>no module-info] --> BP[Add external JARs<br/>to Classpath] --> RUN[Create class, paste<br/>CloudSimExample1, Run]
The module-info.java trap

Eclipse (2019-06 and later) offers to create module-info.java for new projects. With a module descriptor present, classic JARs added to the Classpath are not visible and you get “The package org.cloudbus.cloudsim is not accessible”. Either untick “Create module-info.java” or delete the file (or add the JARs to the Modulepath).

Requirements

  • Windows 10/11, Linux or macOS with 4 GB RAM (Random Access Memory).
  • JDK 17 (or 8/11/21) – Oracle JDK or Eclipse Temurin.
  • Eclipse IDE for Java Developers (2024-xx).
  • cloudsim-3.0.3.zip from the CloudSim GitHub releases page and commons-math3-3.6.1-bin.zip from Apache.

Procedure

Step 1 – Install and verify the JDK

  1. Install the JDK (for example to C:\Program Files\Java\jdk-17).
  2. Set environment variables: System Properties → Environment Variables
    • New system variable JAVA_HOME = C:\Program Files\Java\jdk-17
    • Edit Path → add %JAVA_HOME%\bin
  3. Open a new Command Prompt (old windows do not see the new variables) and check:
C:\Users\student> java -version
java version "17.0.12" 2024-07-16 LTS
Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.12+8-LTS-286, mixed mode, sharing)

C:\Users\student> javac -version
javac 17.0.12

C:\Users\student> echo %JAVA_HOME%
C:\Program Files\Java\jdk-17

All three commands must answer. JAVA_HOME tells tools where Java lives; PATH lets you type java from any folder.

Step 2 – Install Eclipse

  1. Run the Eclipse installer → Eclipse IDE for Java Developers → choose the JDK → Install → Launch.
  2. Select a workspace, for example C:\Users\student\eclipse-workspace.

Step 3 – Download CloudSim and Commons Math

  1. Extract cloudsim-3.0.3.zip to C:\Users\student\Downloads\cloudsim-3.0.3. Its jars folder contains cloudsim-3.0.3.jar, cloudsim-examples-3.0.3.jar and source JARs; examples contains example sources.
  2. Extract Commons Math to C:\Users\student\Downloads\commons-math3-3.6.1 (contains commons-math3-3.6.1.jar).

Step 4 – Create a Java project

  1. File → New → Java Project.
  2. Project name CloudSimLab, JRE Use an execution environment JRE: JavaSE-17.
  3. Untick “Create module-info.java file” → Finish.

Step 5 – Add the JARs to the build path

  1. Right-click CloudSimLab → Build Path → Configure Build Path… → Libraries tab.
  2. Select Classpath → Add External JARs…
  3. Browse to cloudsim-3.0.3\jars, select cloudsim-3.0.3.jar and cloudsim-examples-3.0.3.jar → Open.
  4. Click Add External JARs… again and add commons-math3-3.6.1.jar.
  5. Apply and Close. The project now shows Referenced Libraries with the three JARs.

Step 6 – Run CloudSimExample1

  1. Expand Referenced Libraries → cloudsim-examples-3.0.3.jar → org.cloudbus.cloudsim.examples and open CloudSimExample1 to read it (or open the source from the examples folder).
  2. Right-click src → New → Class: Package org.cloudbus.cloudsim.examples, Name CloudSimExample1, Finish.
  3. Paste the example source (below), save with Ctrl+S.
  4. Run → Run As → Java Application (Ctrl+F11).

Program – CloudSimExample1 (abridged comments)

What the program does, in 7 steps (the numbers match the comments in the code):

  1. Initialise CloudSim for 1 user.
  2. Build one data centre with one host (1 core of 1000 MIPS (Million Instructions Per Second), 2 GB RAM).
  3. Create a broker (the user's agent).
  4. Create one VM (Virtual Machine) (1000 MIPS, 512 MB RAM, 1 core) and give it to the broker.
  5. Create one cloudlet (task) of 400 000 MI (Million Instructions) and bind it to the VM.
  6. Run and then stop the simulation.
  7. Print the results table.
package org.cloudbus.cloudsim.examples;

import java.text.DecimalFormat;
import java.util.*;
import org.cloudbus.cloudsim.*;
import org.cloudbus.cloudsim.core.CloudSim;
import org.cloudbus.cloudsim.provisioners.*;

public class CloudSimExample1 {
    private static List<Cloudlet> cloudletList;
    private static List<Vm> vmlist;

    public static void main(String[] args) {
        Log.printLine("Starting CloudSimExample1...");
        try {
            int num_user = 1;
            Calendar calendar = Calendar.getInstance();
            boolean trace_flag = false;
            CloudSim.init(num_user, calendar, trace_flag);            // 1. initialise

            Datacenter datacenter0 = createDatacenter("Datacenter_0"); // 2. data centre
            DatacenterBroker broker = new DatacenterBroker("Broker");  // 3. broker
            int brokerId = broker.getId();

            vmlist = new ArrayList<Vm>();                                // 4. one VM
            int vmid = 0, mips = 1000, ram = 512, pesNumber = 1;
            long size = 10000, bw = 1000;
            String vmm = "Xen";
            Vm vm = new Vm(vmid, brokerId, mips, pesNumber, ram, bw, size, vmm, new CloudletSchedulerTimeShared());
            vmlist.add(vm);
            broker.submitVmList(vmlist);

            cloudletList = new ArrayList<Cloudlet>();                    // 5. one cloudlet
            long length = 400000, fileSize = 300, outputSize = 300;
            UtilizationModel utilizationModel = new UtilizationModelFull();
            Cloudlet cloudlet = new Cloudlet(0, length, pesNumber, fileSize, outputSize, utilizationModel, utilizationModel, utilizationModel);
            cloudlet.setUserId(brokerId);
            cloudlet.setVmId(vmid);
            cloudletList.add(cloudlet);
            broker.submitCloudletList(cloudletList);

            CloudSim.startSimulation();                                  // 6. run
            CloudSim.stopSimulation();
            printCloudletList(broker.getCloudletReceivedList());         // 7. results
            Log.printLine("CloudSimExample1 finished!");
        } catch (Exception e) {
            e.printStackTrace();
            Log.printLine("Unwanted errors happen");
        }
    }

    private static Datacenter createDatacenter(String name) {
        List<Host> hostList = new ArrayList<Host>();
        List<Pe> peList = new ArrayList<Pe>();
        peList.add(new Pe(0, new PeProvisionerSimple(1000)));
        hostList.add(new Host(0, new RamProvisionerSimple(2048), new BwProvisionerSimple(10000),
                1000000, peList, new VmSchedulerTimeShared(peList)));
        DatacenterCharacteristics characteristics = new DatacenterCharacteristics(
                "x86", "Linux", "Xen", hostList, 10.0, 3.0, 0.05, 0.001, 0.0);
        Datacenter datacenter = null;
        try {
            datacenter = new Datacenter(name, characteristics, new VmAllocationPolicySimple(hostList), new LinkedList<Storage>(), 0);
        } catch (Exception e) { e.printStackTrace(); }
        return datacenter;
    }

    private static void printCloudletList(List<Cloudlet> list) {
        String indent = "    ";
        Log.printLine();
        Log.printLine("========== OUTPUT ==========");
        Log.printLine("Cloudlet ID" + indent + "STATUS" + indent + "Data center ID" + indent + "VM ID"
                + indent + "Time" + indent + "Start Time" + indent + "Finish Time");
        DecimalFormat dft = new DecimalFormat("###.##");
        for (Cloudlet c : list) {
            Log.print(indent + c.getCloudletId() + indent + indent);
            if (c.getCloudletStatus() == Cloudlet.SUCCESS) {
                Log.print("SUCCESS");
                Log.printLine(indent + indent + c.getResourceId() + indent + indent + indent + c.getVmId()
                        + indent + indent + dft.format(c.getActualCPUTime()) + indent + indent
                        + dft.format(c.getExecStartTime()) + indent + indent + dft.format(c.getFinishTime()));
            }
        }
    }
}

Virtual lab · CloudSim · 30 min

Install CloudSim in Eclipse and run your first simulation

Verify the JDK, create a Java project, add the CloudSim JARs to the build path, avoid the module-info trap, then copy and run CloudSimExample1.

Open lab

Output

Example output for the settings in this lesson:

Starting CloudSimExample1...
Initialising...
Starting CloudSim version 3.0
Datacenter_0 is starting...
Broker is starting...
Entities started.
0.0: Broker: Cloud Resource List received with 1 resource(s)
0.0: Broker: Trying to Create VM #0 in Datacenter_0
0.1: Broker: VM #0 has been created in Datacenter #2, Host #0
0.1: Broker: Sending cloudlet 0 to VM #0
400.1: Broker: Cloudlet 0 received
400.1: Broker: All Cloudlets executed. Finishing...
400.1: Broker: Destroying VM #0
Broker is shutting down...
Simulation: No more future events
CloudInformationService: Notify all CloudSim entities for shutting down.
Datacenter_0 is shutting down...
Broker is shutting down...
Simulation completed.
Simulation completed.

========== OUTPUT ==========
Cloudlet ID    STATUS    Data center ID    VM ID    Time    Start Time    Finish Time
    0        SUCCESS        2            0        400        0.1        400.1
CloudSimExample1 finished!

How to read it:

  • 0.1: VM #0 has been created – the VM was ready at 0.1 s.
  • Time 400 – the task needed 400 000 MI ÷ 1000 MIPS = 400 s.
  • Finish Time 400.1 – it started at 0.1 s, so it finished at 0.1 + 400 = 400.1 s.
  • Data center ID 2 – IDs 0 and 1 are already used by CloudSim's own entities (see viva Q8).

Troubleshooting

Error Cause and fix
'java' is not recognized… JDK not on PATH – set JAVA_HOME and %JAVA_HOME%\bin, reopen the prompt
The import org.cloudbus cannot be resolved JARs not on the build path – repeat Step 5
The package org.cloudbus.cloudsim is not accessible module-info.java exists – delete it
NoClassDefFoundError: org/apache/commons/math3/… Commons Math JAR missing
Selection does not contain a main type Run the class that contains public static void main

Conclusion

Check that the example runs without missing-library errors. In CloudSimExample1, find the one data centre, VM and cloudlet. Compare the reported start, run and finish times with the sample output.

Viva questions

  1. What are the software requirements for CloudSim? A JDK, an IDE such as Eclipse, the CloudSim JARs and Commons Math.
  2. Why is a JDK needed instead of only a JRE? The JRE can only run programs; the JDK also has the compiler javac.
  3. What are JAVA_HOME and PATH used for? JAVA_HOME points to the JDK folder; PATH lets you run java/javac from anywhere.
  4. What is the build path / classpath in Eclipse? The list of folders and JARs where Java looks for classes.
  5. Why should module-info.java not be created for a CloudSim project? With it, classpath JARs are not visible, so CloudSim packages are "not accessible".
  6. Why is the Commons Math library required? CloudSim's statistics and power classes use it.
  7. Why does the cloudlet in CloudSimExample1 take 400 seconds? 400 000 MI ÷ 1000 MIPS = 400 s.
  8. Why is the data centre ID 2 and not 0? IDs 0 and 1 are taken by CloudSim's internal entities (the simulation shutdown entity and the CloudInformationService), created first.

Practise this topic

Hands-on virtual lab

Apply what you just read in a realistic, guided simulation. Free with a verified account.

Create a free account to track your progress and unlock virtual labs.