For various reasons I'm still using JMeter 2.x, but this same approach should work in later versions.
In the JMeter install directory there is a lib directory and an ext directory within that. I like to place any external JAR into the lib/ext directory. JMeter does need to be restarted after copying the JAR file over, it will not detect changes automatically.
In this case I'm using the CaseUtils class from the Apache Commons Text API as an example. The JAR file for it can be downloaded from here.
Using a JSR223 Sampler, and the language set to Java, the API can be imported and used as required. Here's just some sample code to demonstrate that it works...
When running this JMeter project, the log viewer will display output generated. It is important to note that all code must be at the Java 1.4 language level, which means you can't use lambdas, try-with-resources, for-each, etc. Just plain old Java code.