I have added the org.dita-ot.dost dependency from Maven Central, and also manually ran mvn:install to install dost-configuration.jar from the DITA-OT download as this JAR isn't included.
Then added DITA-OT 3.7.3 as a resource (excluding the lib directory) and attempting to make use of it through the Java API.
The issue is you need to supply a File pointing to the DITA-OT directory (https://javadoc.io/doc/org.dita-ot/dost/latest/org/dita/dost/ProcessorFactory.html), attempting to use this code to access it via a resource path:
File ditaOtDir = new File(this.getClass().getResource("/dita-ot-3.7.3").toURI());
However when you call ProcessorFactory pf = ProcessorFactory.newInstance(ditaOtDir); this causes Exception in thread "main" java.lang.IllegalArgumentException: DITA-OT directory must be absolute at org.dita.dost.ProcessorFactory.newInstance(ProcessorFactory.java:30) ...
Also attempted to construct the File in a different way, to little success as it causes a different error when calling run on the Processor:
URL ditaOtDirUrl = this.getClass().getResource("/dita-ot-3.7.3");
File ditaOtDir = new File(ditaOtDirUrl.toString()).getAbsoluteFile();
Caused by: Basedir /full/example/path/jar:file:/path/to/this.jar!/dita-ot-3.7.3 does not exist
at org.apache.tools.ant.Project.setBaseDit(Project.java:858)
at org.dita.dost.Processor.run(Processor.java:207)
...
Am I missing something obvious about how to construct this File or is it just not possible to package our JAR like this with DITA-OT included within it?
What you want is not possible, the DITA Open Toolkit needs to be kept as a separate folder as it is not 100% Java (it contains ANT build files, XSLT stylesheets, JAR libraries), it cannot all be packed and run from a JAR library.
I'm linking also to the DITA OT discussion you started on the same theme: https://github.com/orgs/dita-ot/discussions/4229#discussioncomment-6412606 The last comment on that thread is made by Jarno Elovirta, the main DITA OT developer.