Wednesday, May 27, 2020

Compile libgrowl Java 2020

Compile libgrowl Java version




Introduction


Notification is an important software system.

libgrowl is a Java library to send notifications to Growl, there is a C implement libgrowl as well. libgrowl is an open source library.

If you do not have a Growl installed, you can install Growl for Windows, Growl 1.3.x for Mac OS. Growl 2.x is not free anymore, it was selling USD3.99 on macOS App Store.(Is now available free on App Store again). If you don't want to pay for it, you can install the binary from third party (check here), or try to compile one for yourself.

Refer to this blog to download the pre-compile binary http://blogs.umb.edu/michaelbazzinott001/2014/09/21/growl/

libgrowl on Sourceforge and Github


libgrowl sends notification to Growl through network connection, the GNTP network protocol. libgrowl was first hosted on sourceforge.net (by bananewazen) https://sourceforge.net/projects/libgrowl/, later it was mirrored to different Github repositories.

https://github.com/feilimb/libgrowl some said this is the original mirror.
https://github.com/sbower/libgrowl this was modified with maven build.

To compile the libgrowl is a very good practice for Java beginners.

Compile


libgrowl (feilimb)



$ git clone https://github.com/feilimb/libgrowl
$ tree libgrowl
libgrowl
├── build
│ ├── build.xml
│ └── libgrowl.jar
└── src
└── net
└── sf
└── libgrowl
├── Application.java
├── GrowlConnector.java

$ cd build


ant compile and ant jar will do the job

What if you don't have ant and want to do it manually?


$ cd libgrowl/build
$ javac ../src/net/sf/libgrowl/internal/*.java ../src/net/sf/libgrowl/*.java
⇒ no class files?


No class files? class files were generated in the source directory.

$ cd ../src/net/sf/libgrowl
$ java GrowlConnector
Error: Could not find or load main class GrowlConnector

$ java net.sf.libgrowl.GrowlConnector
Error: Could not find or load main class net.sf.libgrowl.GrowlConnector

What happen???

There are many ways to solve the above issue. This is how I do it.
$ cd libgrowl/build
$ javac -d . ../src/net/sf/libgrowl/*.java ../src/net/sf/libgrowl/internal/*.java
⇒ net/sf/libgrowl net/sf/libgrowl/internal
$ java net.sf.libgrowl.GrowlConnector localhost "libgrowl" "libgrowl" "Test" "Hello, world."
(Show Growl notification)

libgrowl (maven)


Maven is a software to build software lifecycle, it will download the necessary dependency from the Internet. It is supposed to make it easier to compile a bigger project, might not be in this case.

Note: The maven software lifecycle $ mvn clean compile test package

I am compiling on macOS Mojave.

$ git clone https://github.com/sbower/libgrowl
$ cd libgrowl
$ mvn compile
⇒ error

I am using Java 8. Compile with deprecated warning, but still able to generate 1.5 binary
$ javac -source 1.5 -target 1.5 HelloWorld.java
⇒ with warning.

But the maven 3.6.3 doesn't support 1.5 binary. My lazy quick fix, change the version in the pom file.

$ edit pom.xml
Change compiler source and target from 1.5 to 1.8

<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>

$ maven package
⇒ error, test not pass.

I just remove all the test cases. After successfully compile, try test the new compiled software following the testing session below.

Testing


Test Growl


You must have the Growl software installed to test. Optional: you can use the command line growlnotify to send notification to Growl.

If you are on macOS, you can install the growlnotify using homebrew.

$ brew install growlnotify

Test libgrowl


$ java -cp ./target/libgrowl.jar net.sf.libgrowl.GrowlConnector "host" "app name" "notification name" "title" "message"

$ java -cp ./target/libgrowl.jar net.sf.libgrowl.GrowlConnector localhost "libgrowl" "libgrowl" "Test" "Hello, world."
or
$ java -cp libgrowl.jar net.sf.libgrowl.GrowlConnector localhost "libgrowl" "libgrowl" "Test" "Hello, world."


No comments: