Setting Google’s Java Styleguide in IntelliJ

Introduction

I’m looking into Google’s Java Stylesheet.  Due to Google being such a large company, I’d imagine it’s been peer-reviewed quite a bit.  I installed it in IntelliJ only to be extremely surprised that two spaces is all that’s set for indentations.

PreReq:

  • Have IntelliJ installed

How To:

wget the style guide:

#wget https://raw.githubusercontent.com/google/styleguide/gh-pages/intellij-java-google-style.xml

Click Settings -> Editor -> Code Style -> Gear -> Import Schema -> IntelliJ IDEA code style XML

IntelliJSettingsCodeStyleScreen

Choose the intellij-java-google-style.xml where you downloaded it.

You can now see the Schema is set to GoogleStyle.

IntelliJSettingsCodeStyleScreenGoogleStyleGuide

 

 

Reference:

Setting up IntelliJ in AWS CentOS 7 with Xming

Introduction

I love my Surface Pro 3 for it’s touch screen, lighweight body, the kick-stand, and it being just generally fast.  The downside is programming in Windows.  The command line leaves something to be desired and PowerShell has never fully grabbed my attention.  Bottom-line, I need a Linux bash shell, otherwise, I’m lost in Windows-land.

This article describes how to have the best of both worlds.  I’m going to setup a Putty Session with X11 Forwarding turned on and remote the display back from an AWS CentOS 7 server.

How To

Setup Xming in Windows 10

  1. Download Xming from: https://sourceforge.net/projects/xming/files/Xming/
    1. Note: This is the last “Free and Open Source” version of Xming, dated 2007.  Much newer paid-for versions can be found here: http://www.straightrunning.com/XmingNotes/
  2. Install the Xming-6-9-0-31-setup.exe
  3. Download Xming Fonts: https://sourceforge.net/projects/xming/files/Xming-fonts/7.7.0.10/
  4. Install Xming-fonts-7-7-0-10-setup.exe

(Note: I’m not sure the Xming-fonts were necessary, I never tested without using them.  They are sync’d up with the version number for the paid-for version of Xming.)

Fix Xming Scaling for the Surface Pro 3

The Surface Pro 3 has great screen resolution, however when exporting the display back from other places, the scaling can be off.  To fix this, I followed the guide from the article “Fix DPI issues with Xming” listed below.

  1. Find the shortcut you are using for Xming, and view the target.
  2. Set the dpi to 120:  “C:\Program Files (x86)\Xming\Xming.exe” :0 -clipboard -multiwindow -dpi 120″
  3. Save the shortcut.
  4. Pin the shortcut to Windows 10

XmingWin10Start

Setup IntelliJ in CentOS 7.4

Setup your Putty session to X11 Forward

  1. Edit the Putty session used to connect to the AWS CentOS server.
  2. Navigate to the Connection->SSH->X11 window.
  3. Check the box to Enable X11 forarding.
  4. Add the X display location as: localhost:0
  5. Save your Putty Session.
  6. Connect to your server.

PuttyConfig

Setup IntelliJ

  1. Download IntelliJ: https://www.jetbrains.com/idea/download/#section=linux
  2. SCP it to your server (I used WinSCP).
  3. Untar it: #tar -xvf ideaIU-2017.3.4.tar.gz
  4. Run it: ./idea-IU-173.4548.28/bin/idea.sh
    1. A first time run will ask you to configure it.
  5. If all went well, you should see nice fonts and excellent scaling.

Fonts:

In the past, I have had to install the dejavu* fonts from yum.  This time, all that was required was the system defaults:

# yum list installed | grep font
fontconfig.x86_64 2.10.95-11.el7 @base
fontpackages-filesystem.noarch 1.44-8.el7 @base
libfontenc.x86_64 1.1.3-3.el7 @base
stix-fonts.noarch 1.1.0-5.el7 @base

Helpful Links

How to Get a Java-Centric Dev Instance Up and Running with AWS EC2 CentOS 7

Prequel:

I’m always setting up one-off dev instances and end-up googling all this information.  I haven’t found a one-stop shop for doing this, so here’s my notes to myself and others.

I’m assuming the following has been completed: (1) Provisioned an instance in EC2 for a CentOS 7 box, (2) Have your SSH key for that instance, and (3) have converted your PEM formatted key into a PPK which is able to be used by Putty.

I’m setting this up using the AWS keys provided.  No passwords.

Set an Elastic IP:

I usually turn off my instance while I’m not using it to save money.  Unfortunately, this means the IP address will change each time I turn it on.  I’ve set an elastic ip for it.  The AWS EC2 T Series requires a “VPC” type elastic ip (not “ec2” type), otherwise you get a cryptic error when trying to attach it: “An error occurred while attempting to associate the address.  The request must contain the parameter instance id.”

 

Connect to your account:

Putty into the server using your PPK.
The default username, for a CentOS 7 box in AWS, is: “centos”.

Set up your user account:

Add a non-default user account for yourself:

#useradd <username>

Add the user to the sudoers group:

#sudo gpasswd -a <username> wheel

The default settings in: /etc/sudoers  does not allow password-less login.  Since we aren’t using a password, we need to modify this file.  Comment out the current wheel line, and uncomment the 2nd one.  It should look this afterward:

Edit the /etc/sudoers file:

## Allows people in group wheel to run all commands
#%wheel ALL=(ALL) ALL

## Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL

Install Java

I prefer to use the tar.gz version of Java and specifically link it in myself, versus using an rpm, or yum to manage that for me.  Lots of pro’s and con’s here.

I downloaded java on my local workstation and scp’d it over to the server.

## Extract java into /opt
# sudo tar -xvf jdk-8u102-linux-x64.tar.gz

## Give it your permissions
# sudo chown -R <username>.<username> jdk*

## Symlink your current java install
# sudo ln -s jdk1.8.0_102 java

Add JAVA_HOME and JAVA_BIN to /home/<user>/.bashrc and to the PATH.

# vi /home/<user>/.bashrc

## Add the following:
# export JAVA_HOME=/opt/java
# export PATH=$PATH:$JAVA_HOME/bin

Either source your bashrc (source ~/.bashrc), or log out and log back in to pick up the new path.

Run the following to verify Java is installed properly:

# java -version

Output:

java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)

Install Maven:

Like Java, I prefer to install Maven on my own.

Download the latest version using wget and install:

# wget http://mirrors.gigenet.com/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz

## Extract maven into /opt
# sudo tar -xvf jdk-8u102-linux-x64.tar.gz

## Give it your permissions
# sudo chown -R <username>.<username> apache-maven*

## Symlink your current java install
# sudo ln -s apache-maven-3.3.9 maven

Add Maven to your .bashrc:

# vi /home/<user>/.bashrc

## Add the following:
# export PATH=/opt/maven/bin:$PATH

Either source your bashrc (source ~/.bashrc), or log out and log back in to pick up the new path.

Run the following to verify Maven is installed properly:

# mvn -v

Output:

Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /opt/maven
Java version: 1.8.0_102, vendor: Oracle Corporation
Java home: /opt/jdk1.8.0_102/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-327.10.1.el7.x86_64", arch: "amd64", family: "unix"

There you have it!  Up and running with Java and Maven on CentOS 7 EC2.  Next step is to install your favorite ide, or maybe just git clone and compile something from github.

Sources: