Report System and Environment Diagnostics at Runtime

I originally started this to determine which version of Processing was being used in VS Code when I changed the settings.json file to different versions.

And somehow that got missed!

VS Code for Processing settings.json file:

{
    "astyle-format.args": "--style=whitesmith --indent=tab=4 --indent=spaces=4",
    "astyle-format.path": "\"D:\\Program Portable\\AStyle\\bin\\astyle.exe\"",
    "processing.version": "4.4.7",
    "[Processing]": {
        
    },
    "[jsonc]": {
        
        "editor.quickSuggestions": {
            "strings": true
        },
        "editor.suggest.insertMode": "replace"
    },
    "files.associations": {
        "*.pde": "cpp"
    }
}

Processing code to report version number:


//==============================================================================
// TITLE: Report Location of Processing Core for Version Number
//------------------------------------------------------------------------------
// DESCRIPTION:
// This sketch demonstrates two cross-platform methods for reliably locating
// the file path of the Processing core library (core.jar) using the
// ProtectionDomain of the PApplet class.
//
// AUTHOR:  glv
// DATE:    2025-10-17
// VERSION: 1.0.2
//
// REFERENCE:
// https://stackoverflow.com/questions/320542/how-to-get-the-path-of-a-running-jar-file
//==============================================================================

import processing.core.PApplet; // Import is implicit but good practice
import java.io.File;            // Necessary for the File object
import java.net.URI;            // Necessary for the URI object

void setup()
    {
    // Get Processing version path and version from core.jar
    getVersion_1();
    println();
    getVersion_2();

    // Stop the sketch
    exit();
    }

void draw()
    {
    }

void getVersion_1()
    {
    String path = "Error: Could not retrieve path";

    //Get Processing Folder Path()

    try
        {
        path  = processing.core.PApplet.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath();;
        }
    catch (Exception e)
        {
        println("Error: Could not retrieve path");
        }

    // Extract core version

    int lastSlashIndex = path.lastIndexOf('/'); //For Windows
    String lastElement = "Extraction Failed";

    if (lastSlashIndex != -1)
        {
        lastElement = path.substring(lastSlashIndex + 1);
        }

    // Print the result to the console
    println("Path:");
    println(path);
    println("Core:");
    println(lastElement);
    }

void getVersion_2()
    {
    String path = "Error: Could not retrieve path";

    try
        {
        URI coreURI = PApplet.class.getProtectionDomain().getCodeSource().getLocation().toURI();
        File coreFile = new File(coreURI);
        path = coreFile.getAbsolutePath();
        }
    catch (Exception e)
        {
        // Catches errors related to URI conversion

        println("An error occurred while finding the path:");
        e.printStackTrace();
        }

    // Extract core version

    int lastSlashIndex = path.lastIndexOf('\\'); // This is different than the other version!
    String lastElement = "Extraction Failed";

    if (lastSlashIndex != -1)
        {
        lastElement = path.substring(lastSlashIndex + 1);
        }

    // Print the result to the console
    println("Path:");
    println(path);
    println("Core:");
    println(lastElement);
    }

The above worked and this is the workflow:

  • Change version number in settings.json and save the file!
  • Run the Processing sketch
  • Read report in the console.

This pops up if the version entered is not found:

Subsequent runs of the code use the last version that was used but the settings.json remains unchanged.

I was also sorting out issues related to this and was hoping to find libraries being used behind the scenes:
Error: The package “javax.xml.bind” does not exist. You might be missing a library - #8 by glv
That is still a work in progress…

:)