How to create Macro JAR from IntelliJ IDEA

The Macro Documentation mentions these steps:

  • Compile the HelloWorld.java file. The following jar files from the program/classes directory of a OpenOffice.org installation must be in the classpath: ridl.jar, unoil.jar, jurt.jar
  • Create a HelloWorld.jar file containing the HelloWorld.class file

How would these steps be accomplished in IntelliJ IDEA (or even, for that matter, from the command line?)

My attempt below resulted in the following error when trying to run the macro.

  1. Add provided HelloWorld.java to ./src
  2. Mark ./src as Sources Root
  3. Define Project compiler output path in Project Settings
  4. Add juh.jar, jurt.jar, officebean.jar, ridl.jar, and unoil.jar to Project Libraries
  5. Add a JAR Artifact From modules with dependencies, no Main Class
  6. Remove LibreOffice .jar files from output (automatic behavior was to include them extracted, but I think that’s unnecessary since LibreOffice clearly already has a copy)
  7. Generate a manifest file

Error:

com.sun.star.uno.RuntimeException: [jni_uno bridge error] UNO calling Java method invoke: non-UNO exception occurred: java.lang.NullPointerException
java stack trace:
java.lang.NullPointerException
    at sun.misc.Resource.getBytes(Resource.java:143)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:450)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:367)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.sun.star.script.framework.provider.java.ScriptImpl.invoke(ScriptProviderForJava.java:238)

My guess would be that this error is indicating that the HelloWorld class was not found in the JAR.

What steps are missing? Or what might I need to do in order to further diagnose the problem?

The missing step was to set the full package path. I discovered this by comparing the contents of my JAR with the example one.

So the full list of steps is

  1. Add provided HelloWorld.java to ./src/com/Company/Project/
  2. Mark ./src as Sources Root
  3. Define Project compiler output path in Project Settings
  4. Add juh.jar, jurt.jar, officebean.jar, ridl.jar, and unoil.jar to Project Libraries
  5. Add an Artifact of type JAR with option From modules with dependencies, and no Main Class
  6. Remove the step 4 LibreOffice .jar files from Output Layout
  7. Generate a manifest file
  8. Modify org.libreoffice.example.java_scripts to match the actual path from src to HelloWorld.java

Building this artifact through the build menu should now output a JAR that works in LibreOffice write without throwing an error.