2017-02-05

5: To Build the Environment for Developing UNO Extensions (LibreOffice Extensions or Apache OpenOffice Extensions), for Linux, Part Two

<The previous article in this series | The table of contents of this series | The next article in this series>

Main body START

To Know How to Handle (Read or Write) LibreOffice or Apache OpenOffice Writer or Calc Documents via Extensions from Java or Macro Programs

To Build the Environment for Developing UNO Extensions, for Linux, Part Two

-Hypothesizer

Third, Oracle JDK will be installed. As Oracle JDK isn't included in the official OS packages repositories, a PPA (Private Package Archive, which is an unofficial packages repository) is used here. It can be installed using the add-apt-repository and apt-get commands, like this.

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
-Rebutter

How can we install Oracle JDK in another way or on other Linux distributions?

-Hypothesizer

If using PPAs isn't an option, we can download a tar.gz file from the Oracle Web site, and install it using the file. . . . For other distributions, if Oracle JDK is included in their official or unofficial packages repositories, we can use them. Otherwise, we can download a rpm or tar.gz file from the Oracle Web site, and install it using the file.

-Rebutter

Oh.

-Hypothesizer

Then, the JDK binary directory will be added to the OS command path and a necessary environment variable will be set. In fact, on this platform, the JDK binary directory doesn't need to be added to the OS command path because symbolic links to necessary JDK commands are automatically created in /usr/bin. Otherwise, we can add it in whatever way. As for the environment variable, here, bash (a Unix shell) is used, and the environment variable is set in the system-wide .bashrc file, /etc/bash.bashrc. Or we can set it in whatever other way. . . . Here, this is set at the top most part of the .bashrc file.

export JAVA_HOME=$(readlink -f $(which javac) | sed "s/\/bin\/javac$//")
-Rebutter

. . . What does that do?

-Hypothesizer

That gets the original path of the javac symbolic link, and extract the necessary part.

-Rebutter

Um, . . . I see.

-Hypothesizer

When a new terminal is opened, the setting should be reflected in the environment of the terminal.

-Rebutter

OK.

-Hypothesizer

Forth, Ant will be installed. If we don't use Ant, this isn't necessary. For Lubuntu 16.04, Ant is included in the OS packages repositories. So, it can be installed using the apt-get command, like this.

sudo apt-get install ant
-Rebutter

OK.

-Hypothesizer

Then, the Ant binary directory will be added to the OS command path, and a necessary environment variable will be set. In fact, in this platform, the Ant binary directory doesn't need to be added to the OS command path because a symbolic link to the necessary Ant command is automatically created in /usr/bin. Otherwise, we can add it in whatever way. As for the environment variable, here, it is set in the user specific .bashrc file, ~/.bashrc. Or we can set it in whatever other way. Here, this is set at the top most part of the .bashrc file.

export ANT_HOME=$(readlink -f $(which ant) | sed "s/\/bin\/ant$//")

When a new terminal is opened, the setting should be reflected in the environment of the terminal.

-Rebutter

OK.

-Hypothesizer

Fifth, Gradle will be installed. If we don't use Gradle, this isn't necessary. . . . Gradle can be downloaded from the Gradle download Web page. Here, the binary only distribution is downloaded. We create an arbitrary directory (here, ~/my-applications/bin), and expand the downloaded zip file there.

-Rebutter

All right.

-Hypothesizer

Then, the Gradle binary directory will be added to the OS command path, and a necessary environment variable will be set. Here, the OS command path and the environment variable are set in the user specific .bashrc file, ~/.bashrc. Or we can set them in whatever other way. Here, this is set at the top most part of the .bashrc file.

export GRADLE_HOME=~/my-applications/bin/gradle-3.1
export PATH=$GRADLE_HOME/bin:$PATH

When a new terminal is opened, the setting should be reflected in the environment of the terminal.

-Rebutter

I see.

-Hypothesizer

Sixth, the Java runtime to be used by LibreOffice will be set. . . . We can set it like this: run LibreOffice Calc; click 'Tools' on the menu; click 'Options'; click 'Advanced'; check 'Use a Java runtime environment'; select the Oracle JRE; click 'OK'.

-Rebutter

OK.

-Hypothesizer

Seventh, this isn't mandatory, but wmctrl (a command used to control windows in EWMH (NetWM)-compatible X Window window managers) will be installed. In a Ant build file and a Gradle build script used in this series, wmctrl is used to shutdown LibreOffice gracefully (which means to let users close opened documents before LibreOffice is shutdown) before UNO extensions are installed into LibreOffice. If wmctrl isn't installed, users can just shutdown LibreOffice manually, as builds just wait until LibreOffice is shutdown.

-Rebutter

Hmm, we have to shutdown LibreOffice before UNO extensions are installed into LibreOffice?

-Hypothesizer

In fact, we can install UNO extensions into LibreOffice using a menu item of LibreOffice while LibreOffice is up, but anyway, we have to restart LibreOffice after the installation for the UNO extensions to become usable.

-Rebutter

I see.

-Hypothesizer

Now, the environment to develop UNO extensions has been built for Linux.

Main body END

References

  • Oracle. (n/a). Java SE Downloads. Retrieved from http://www.oracle.com/technetwork/java/javase/downloads/index.html
  • The Apache Software Foundation. (n/a). Binary Distributions. Retrieved from http://ant.apache.org/bindownload.cgi
  • Gradle Inc. (n/a). Download Gradle 3.1. Retrieved from https://gradle.org/gradle-download/
  • Wikipedia. (2016/07/21). wmctrl. Retrieved from https://en.wikipedia.org/wiki/Wmctrl

<The previous article in this series | The table of contents of this series | The next article in this series>