Ask Your Question
0

How to create Macro JAR from IntelliJ IDEA

asked 2017-06-06 11:38:10 +0200

Max Pixel gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
0

answered 2017-06-07 10:04:45 +0200

Max Pixel gravatar image

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.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-06-06 11:38:10 +0200

Seen: 492 times

Last updated: Jun 07 '17