Have you worked with the oshi library

Has anybody worked with the oshi library?
Regards
huchavacia

Hello @huchavacia,

Welcome to the forum.

Yes. First time using it.

Required jar files for Windows 10:

Reference:

:slight_smile:

Thanks for the reply
I undestand the files have to be in the code directory, not in processing libraries ditectory.
I have a newer version 7-4- 0 taken from the maven website.
If you could share your sketch i would be obliged.
It’s been quite a while since i last made a program and I’m not fluent with github
Regards

That did not work for me with Processing 4.5.5 on W10.

These are the libraries in JAR files that I was successful with and shared in previous post:

  • oshi-core-shaded-6.1.0.jar bundles many of its dependencies
  • jna-5.19.1.jar required
  • jna-platform-5.19.1.jar required

Once you have those then you can start.

You have to start somewhere!

The GitHub repository I shared has a SystemInfoTest.java example from which I extracted what I needed and adapted to work with Processing.

Minimal example:

There is a learning curve to all of this and I spent a couple of hours on research, getting this library to work and understanding some of the errors vs warnings.

Adding an external Java library is a challenge on top of just learning Processing.
You need to invest the time in Processing and Java initially.

Resources:

When running the sketch, all packages found in the .jar file will automatically be added as import statements in the sketch (though invisible to the user).

This is what Processing generates “under the hood”:

Invisible to the user
/* autogenerated by Processing revision 1314 on 2026-07-20 */
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;

import com.sun.jna.*;
import com.sun.jna.internal.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.*;
import com.sun.jna.platform.*;
import com.sun.jna.platform.bsd.*;
import com.sun.jna.platform.dnd.*;
import com.sun.jna.platform.linux.*;
import com.sun.jna.platform.mac.*;
import com.sun.jna.platform.unix.*;
import com.sun.jna.platform.unix.aix.*;
import com.sun.jna.platform.unix.solaris.*;
import com.sun.jna.platform.win32.*;
import com.sun.jna.platform.win32.COM.*;
import com.sun.jna.platform.win32.COM.tlb.*;
import com.sun.jna.platform.win32.COM.tlb.imp.*;
import com.sun.jna.platform.win32.COM.util.*;
import com.sun.jna.platform.win32.COM.util.annotation.*;
import com.sun.jna.platform.wince.*;
import oshi.hardware.*;
import oshi.hardware.platform.mac.*;
import oshi.hardware.platform.unix.freebsd.*;
import oshi.hardware.platform.unix.*;
import oshi.hardware.platform.unix.openbsd.*;
import oshi.hardware.platform.unix.solaris.*;
import oshi.hardware.platform.unix.aix.*;
import oshi.hardware.platform.linux.*;
import oshi.hardware.platform.windows.*;
import oshi.hardware.common.*;
import oshi.util.*;
import oshi.util.tuples.*;
import oshi.util.platform.mac.*;
import oshi.util.platform.unix.freebsd.*;
import oshi.util.platform.unix.openbsd.*;
import oshi.util.platform.unix.solaris.*;
import oshi.util.platform.linux.*;
import oshi.util.platform.windows.*;
import oshi.*;
import oshi.driver.mac.net.*;
import oshi.driver.mac.*;
import oshi.driver.mac.disk.*;
import oshi.driver.unix.*;
import oshi.driver.unix.freebsd.*;
import oshi.driver.unix.freebsd.disk.*;
import oshi.driver.unix.openbsd.disk.*;
import oshi.driver.unix.solaris.*;
import oshi.driver.unix.solaris.disk.*;
import oshi.driver.unix.solaris.kstat.*;
import oshi.driver.unix.aix.*;
import oshi.driver.unix.aix.perfstat.*;
import oshi.driver.linux.proc.*;
import oshi.driver.linux.*;
import oshi.driver.windows.perfmon.*;
import oshi.driver.windows.*;
import oshi.driver.windows.wmi.*;
import oshi.driver.windows.registry.*;
import oshi.annotation.concurrent.*;
import oshi.software.common.*;
import oshi.software.os.*;
import oshi.software.os.mac.*;
import oshi.software.os.unix.freebsd.*;
import oshi.software.os.unix.openbsd.*;
import oshi.software.os.unix.solaris.*;
import oshi.software.os.unix.aix.*;
import oshi.software.os.linux.*;
import oshi.software.os.windows.*;
import oshi.jna.platform.mac.*;
import oshi.jna.platform.unix.*;
import oshi.jna.platform.linux.*;
import oshi.jna.platform.windows.*;
import org.slf4j.impl.*;
import org.slf4j.event.*;
import org.slf4j.helpers.*;
import org.slf4j.*;
import org.slf4j.spi.*;

import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;

public class ohsi_1_0_0_PF extends PApplet {

  public void setup() {

/*
 * SYSTEM MONITORING DEPENDENCIES (OSHI & JNA)
 *
 * - oshi-core-shaded-6.1.0.jar: Shaded OSHI core library providing Java APIs
 *   for accessing hardware and operating system information.
 *
 * - jna-5.19.1.jar: Java Native Access library used by OSHI to interface
 *   with native operating system APIs.
 *
 * - jna-platform-5.19.1.jar: Platform-specific JNA mappings providing access
 *   to native OS APIs and structures for Windows, Linux, and macOS.
 */

// Imports not required with jars in code folder
// List these later to show hat is used

  
SystemInfo si = new SystemInfo();  
OperatingSystem os = si.getOperatingSystem();
  
// Prints to console:
println();

println((os));
println();

println(":-)");

noLoop();
  }

  static public void main(String[] passedArgs) {
    String[] appletArgs = new String[] { "ohsi_1_0_0_PF" };
    if (passedArgs != null) {
      PApplet.main(concat(appletArgs, passedArgs));
    } else {
      PApplet.main(appletArgs);
    }
  }
}

:-)

Update

I did some further exploration.

Keep in mind that the library has dependencies and these are listed in the Maven repository for the library.

I used the oshi-core-6.6.3.jar (Java 17) to work with Processing 4.5.5 (Java 17).

This update generated no warnings:

I am not an expert by any means on any of this but with experience and persistence I will work toward a solution or a compromise.

Cool library!

Lots to explore with it:

:)

When I try to add ‘import org.slf4j.Logger’ I get this error message:

Is there any graceful way to get around this? I am reluctant to alter all of these apps by deleting the competing slf4j.jar files in order to run this one.

Addendum:

The only way that I could get ‘oshi’ to run was to move all the slf4j.jar files to a separate folder in each of the last four apps listed in the error dialog. I had no way to remove the Serial (part of Processing) files, but it ran anyway without doing this. I used the three libraries described above: