Building the Java client

Building the java client in NetBeans : installation and configuration.


We’ve got the magic mirror software going.  We’ve got Alexa going.  We could stop right now as do much of the smart mirror projects on the internet at then moment, but people that know me well, will know that i’m not about to stop.

One of the major problems I have with the current solution is that it requires the manual authentication using the web browser every single time.  Furthermore, the authentication only lasts for one hour, and that’s not really cool if you want to use the mirror during the day.

There aren’t many resources on how to do that, but will be looking for a solution.

An important part is the fact that I’ll be editing the Java code of the java client, and possible create an own application that takes care of the authentication.  That way I can get rid of the companion service which now takes care of the browser authentication.

What to do?  Get the java application to build on the Raspberry Pi.

Developing needs some screen real-estate, and with the current VNC resolution we’re not going to cut it.  That’s why i’m changing my screen resolution to 1920×1080.  You can find how to do this in this post.

There are several IDE’s that allow the editing of code, but I’ll be choosing NetBeans.

However, before doing so, we need to install the Java JDK.  JDK stands for Java Development Kit.  You can download the JDK from the oracle site (Java is an oracle product), but there’s an easier way to get it.  Just run the following command in the terminal (while connecting through ssh, or via a terminal in VNC)

sudo apt-get install oracle-java8-jdk

The next thing to do is get netbeans.  Take over the screen of the Pi using VNC and navigate to the NetBeans site, to the downloads section :

The binary to download is “Java SE Installer Linux Netbeans 8.2” (or a later version)

What it actually downloads is a bash script file (suffix .sh), which actually contains some code that can be interpreted by the shell (which can be accessed when you start a terminal).

By default, however, this script is not executable.  You have to change the access  permissions of the file.  The way to do that is by using the chmod command.

While you’re in the directory the script is in type :

chmod 777

Next, execute sh file

sudo ./

At some point during the installation you might get an error that resembles this one.

The JDK is missing and is required to run some NetBeans modules.

Schermafbeelding 2017-01-08 om 22.55.27.png

NetBeans is an IDE (integrated development environment) that supports building multiple types of code (not only Java code), and also supports multiple frameworks and tools that can be used in conjunction with NetBeans.  They are called plugins, or modules.  Some of these require the JDK to install them.  We haven’t told NetBeans where the location of the JDK is yet, so the error comes up.  For now, just ignore the error and click “Disable Modules and Continue”.  You might have to do this multiple times.

When everything is done installing you are able to start the NetBeans IDE.  It’s time to try and open the Java Client, downloaded from the GitHub of Amazon Voice Services.  If everything went down in your installation as it did in mine, you probably won’t be open the Java client because it doesn’t recognise the folder as being a project folder.  The reason for this is, that the Java Client is actually a maven project.

Apache Maven is a software project management and comprehension tool. Based on the concept of a project object model (POM), Maven can manage a project’s build, reporting and documentation from a central piece of information.  You can find more information here.

In order to be able to open the maven project folder, we have to install a plugin.

In NetBeans, from the “Tools” menu, choose “Plugins“.

Schermafbeelding 2017-01-08 om 23.07.15.png

In the “installed” plugins you should find the “Maven” plugin, but you can see the checkbox isn’t checked because it isn’t activated.  You can check it and click the “Activate” button below, but you’ll probably notice that won’t work.  This is one of the modules that could not be activated during the installation because NetBeans didn’t know the path to the JDK.

So now it’s time to configure the JDK for Netbeans.  This is done through a configuration file.  Start a terminal session and navigate to the NetBeans installation folder.  On my Pi that’s the /user/local/netbeans folder.

Navigate to the “etc” folder and open the the “netbeans.conf” file using nano:

sudo nano netbeans.conf

locate the line where it says  netbeans_jdkhome=”” and enter the correct path to the JDK.  In my case that’s in the /usr/lib/jvm/java-8-oracle directory.

Schermafbeelding 2017-01-08 om 23.11.34.png

Ctrl-X y Enter to save.

Now it’s time to activate the plugin.  Restart NetBeans and open the plugins window again.  You should now be able to activate the plugin.  You might have to restart Netbeans again to complete the process.

You should now be able to open the java client folder.  You’ll see it has another icon.

Schermafbeelding 2017-01-08 om 18.25.22.png

In my case I wasn’t able to build the application right away.  It was giving me issues when opening a file. NetBeans keeps telling it can’t open the files because the file encoding is different from UTF-8.   There’s actually a way around this, but we first have to find out in which encoding the files are.  The way to find out is through the “file” command.  Open a terminal and navigate to a directory where you can find .java code files.  Try the following command :

file -i <name of a file>.java

That should show you something like the screenshot below.

Schermafbeelding 2017-01-08 om 23.26.11.png

Here you can see that the file itself has an encoding of “us-ascii“.  We need to tell NetBeans that the project contains files in this encoding.

Open a terminal and navigate to the NetBeans installation folder, like before, and open the “netbeans.conf ” file again, just like we did when changing the JDK path.  Search for the “netbeans_default_options” line and append the following :


Schermafbeelding 2017-01-10 om 22.22.11.png

Ctrl-X y Enter to save, and restart NetBeans.

The JavaClient project should open with it.  Right-click on the project, and choose “Properties”.

Schermafbeelding 2017-01-10 om 22.24.11.png

In the “sources” category, choose “US-ASCII” as an encoding.

Schermafbeelding 2017-01-10 om 22.24.56.png

After restarting NetBeans it should be able to read the files.  In my case however there was still a problem in packages with a suffix of “.appleDouble”.  I just deleted them so I was left only with packages that compiled without a problem.  I was able to build the project by right-clicking the project, and choosing Build.

Try and run the application by clicking the green triangle in the menu bar.

Schermafbeelding 2017-01-10 om 22.26.58.png

It prompts you to choose a main class. The class that will be used to start the application.  It gives you only 1 proposition actually.  Just select it, and choose to remember it permanently.

Schermafbeelding 2017-01-10 om 22.08.20.png

OK, this could take a while.  The Raspberry Pi is not the most speedy thing out there, but it should work.  I got the main interface, so I’m a happy camper.

Schermafbeelding 2017-01-10 om 22.31.19.png

Good Luck!



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s