Skip to content

Setting up Java development environment

ferng edited this page Nov 18, 2020 · 25 revisions

I had too much grief with STS, it stomped all over my repositories (filling them up with maven shit like configs and local sources, everything took hours to do (what with maven pulling down and refreshing stuff all the time), then STS started crashing, went back to Eclipse which was a bit better, but not much. In the end I just jumped to Intellij for Java stuff, works like a charm.

Java 8

Install Windows

%JAVA_HOME% = C:\Program Files\Java\jdk1.8.0_66
add to PATH = %JAVA_HOME%\bin

Install Linux

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

Java 11

cd ~/Downloads
sudo tar xfvz OpenJDK11U-jdk_x64_linux_openj9_11.0.7_10_openj9-0.20.0.tar.gz --directory /usr/lib/jvm
  • Update environment permanently if that's what you want
sudo vi /etc/profile.d/jdk.csh 
sudo vi /etc/profile.d/jdk.sh

Migrate project from Java 8 to Java 11

  • Install java 11
  • Upgrade to Maven 3.6.0 pom.xml
        <maven-surefire.version>2.22.2</maven-surefire.version>
        <maven-failsafe.version>2.22.2</maven-failsafe.version>
        <maven-compiler.version>3.8.0</maven-compiler.version>

Install Java Documentation

mkdir -p ~/dgedit/javaDev/docs/java  ~/dgedit/javaDev/docs/javafx
cd ~/dgedit/javaDev/docs/java
cp ~/../Downloads/jdk-*-apidocs.zip .
unzip jdk-*-apidocs.zip
rm jdk-*-apidocs.zip
cd ~/dgedit/javaDev/docs/javafx
cp ~/../Downloads/javafx-*-apidocs.zip .
unzip javafx-*-apidocs.zip
rm javafx-*-apidocs.zip

Multiple installs

#set up new one
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/jdk1.8.0_202/bin/java 3
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/jdk1.8.0_202/bin/javac 3

#list options
sudo update-alternatives --list java
sudo update-alternatives --list javac

#change options
sudo update-alternatives --config java
sudo update-alternatives --config javac

vi ~/.profile
# JAVA 
#export JAVA_HOME=/usr/lib/jvm/java-9-oracle
export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_202

Tools

/usr/lib/jvm/java-7-oracle/bin/jvisualvm

# debug
-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=1044

Intellij

Install

cd /opt
sudo cp ~/Downloads/ideaIC-2019.2.4.tar.gz .
sudo tar -xvf ideaIC-2019.2.4.tar.gz

#make intellij dir updatable by me
sudo chown -R fern:fern /opt/idea-IC-192.7142.36/

#or to a whole group
sudo chgrp -R dev /opt/idea-IC-192.7142.36/

Shortcuts

lubuntu

cd ~/.local/share/applications
cp ~/prog/config/intellij/idea.desktop .
update directory names

gnome

cd ~/.local/share/applications/
vi jetbrains-idea-ce.desktop

[Desktop Entry]
Version=1.0
Type=Application
Name=IntelliJ IDEA Community Edition
Icon=/opt/idea-IC-202.7319.50/bin/idea.png
Exec="/opt/idea-IC-202.7319.50/bin/idea.sh" %f
Comment=The Drive to Develop
Categories=Development;IDE;
Terminal=false
StartupWMClass=jetbrains-idea-ce

Configuration

Item Value
Appearance & Behaviour > Appearance > Animate Windows Off
Editor > Code Style > Scheme Fern
Editor > Code Style > Right Margin 120
Editor > Code Style > Line Separator for new files Unix and OSX (\n)
Editor > General > Rich Text Copy Off
Editor > General > Code Folding All Off
Editor > General > Breadcrumbs > Off
Editor > General > Appearance > Show parameter name hints Off
Editor > General > Appearance > Show external annotations inline Off
Editor > File and Code Templates Remove all headers
Tools > Web Browsers Chrome
Keymap > Tool Windows > Maven Projects Alt+0
Keymap > Other > New Folder Ctrl+N
Keymap > Other > New File Ctrl+N
Keymap > Main Menu > Build > Build Artifacts
Keymap > Tool Windows > Maven Projects Alt+0
Keymap > Tool Windows > Maven Projects Alt+0
Keymap > Main Menu > Window > Editor Tabs > Split Horizontally Ctrl+Alt+Slash
Keymap > Main Menu > Window > Editor Tabs > Unsplit Ctrl+Alt+Shift+Slash
Keymap > Main Menu > VCS > Local History > Show History Ctrl+Alt+Q, Ctrl+Alt+H

Plugins

Plugin
PMD
Findbugs
Checkstyle

Import Layouts

Editor > Code Style > Java > Imports
import all other imports
blank
javax.*
java.*
blank
com.thecrunchycorner.*
blank
static all other imports

Hot Deployment

project structure | artifacts | exploded war | output directory
C:\Users\fernandog\Documents\envs\apache-tomcat-8.0.30\webapps\runlog-web

Eclipse

Install

  • Download eclipse
#as fern
cd ~/Downloads
tar -zxvf eclipse-jee-kepler-SR1-linux-gtk-x86_64.tar.gz

#as root
mv /home/fern/Downloads/eclipse /opt

Configuration

  • window > preferences > general > workspace > "New text file line delimiter".
  • window > preferences > general > editors > text editors > display tab width: 2
  • window > preferences > general > editors > text editors > insert spaces for tabs
  • window > preferences > general > editors > text editors > show print margin: 80
  • window > preferences > general > appearance > colors and fonts > basic > text editor fonts > 9
  • window > preferences > general > appearance > colors and fonts > basic > header font > 11
  • window > preferences > general > perspectives > java : make default
  • window > preferences > general > keys > Add BookMark > ALT + B
  • window > preferences > general > keys > Toggle ToolBar > ALT + 2
  • window > preferences > java > editor > folding > deselect "Enable folding..."
  • window > preferences > java > editor > save actions:
    • Add 'this' qualifier to unqualified field accesses
    • Add 'this' qualifier to unqualified method accesses
    • Change non static accesses to static members using declaring type
    • Convert control statement bodies to block
    • Add final modifier to private fields
    • Put expressions in parentheses
    • Add missing '@Override' annotations
    • Add missing '@Override' annotations to implementations of interface methods
    • Add missing '@Deprecated' annotations
    • Remove unnecessary casts
    • Remove trailing white spaces on all lines
  • window > preferences > java > installed jre > add > Standard VM > jdk directory
  • window > preferences > java > installed jre > edit > Default VM arguments: -ea
  • window > preferences > ant > editor > folding > deselect "Enable folding..."
  • window > preferences > ant > editor > formatter > tab size : 2
  • window > preferences > ant > editor > formatter > deselect: "Use tab character..."
  • window > preferences > run/debug > console > console buffer size : 400000
  • window > preferences > run/debug > console > display tab width : 4
  • window > preferences > run/debug > console > show when program writes stdout : disable
  • window > preferences > run/debug > console > background colour : 0
  • window > preferences > run/debug > console > stdout colour : 255

Install eclipse plug ins

Find Bugs

# as root
cd /opt/eclipse/plugins
cp ~/edu.umd.cs.findbugs.plugin.eclipse_2.0.3.20131105-14951.zip .
unzip edu.umd.cs.findbugs.plugin.eclipse_2.0.3.20131105-14951.zip
rm edu.umd.cs.findbugs.plugin.eclipse_2.0.3.20131105-14951.zip

XML Editor

# as root
cd /opt/eclipse/plugins
cp /home/fern/Downloads/tk.eclipse.plugin.htmleditor_2.1.0.jar .

SQL Editor

NOT FOR HSQLDB

  • Help > Install New Software:
  • Work with: --All Available Sites--
    • Database Development: Data Tools Platform Extender SDK

Clone this wiki locally