IntelliJ IDEA

Preparation & Installation

One time instructions to get it installed

Downloads

Resources

For the class, let's all use the exact same JDK to make things easier.

Use IntelliJ to download from AdoptOpenJDK (HotSpot) and get the latest LTS release. More information.

About the JDK

Remove SDKs from IntelliJ

Download JDKs through IntelliJ or from https://adoptopenjdk.net/.

Getting Started

One time instructions once it is installed

Before you run IntelliJ IDEA for the first time

  • Register at jetbrains.com/student if you haven't already

    • Save your user name and password in OneDrive or somewhere

The first time you run IntelliJ IDEA

  • Accept license and click through options. You don't need to do anything special and everything can be modified later.

    • Activate with your JetBrains Account

For Regular non-graphical Java Projects

  • From Welcome screen...

    • Create New Project, Java

    • Choose Project SDK or click New -> JDK and browse to jdk folder, like C:\OpenJDK\jdk-11.0.2

    • Next, check box to Create project from template

    • Next, see New Projects section for important name and location information, Finish

Resources

Settings

  • Set IntelliJ to use Google Style in one of two ways:

    • 1)

      • Download and unzip the Google Style Guide https://github.com/google/styleguide

      • IntelliJ Settings (File -> Settings or Ctrl+Alt+S or Customize -> All settings.. from the Welcome screen)

      • Editor -> Code Style -> Java -> gear icon -> Import Scheme -> IntelliJ... -> browse to unziped Google Style Guide and choose intellij-java-google-style.xml

    • 2)

      • Go to https://plugins.jetbrains.com/plugin/8527-google-java-format click the down arrow next to the latest version to download it

      • IntelliJ Settings (File -> Settings or Ctrl+Alt+S or Customize -> All settings.. from the Welcome screen)

      • Plugins -> gear icon -> Install Plugin from Disk -> browse to downloaded zip file -> Restart IDE -> Enable plugin from popup window

  • IntelliJ Settings (File -> Settings or Ctrl+Alt+S or Customize -> All settings.. from the Welcome screen)

    • Editor -> Code Style

      • Hard wrap at 100 or 80

      • Visual guides 100 or 80

    • Search Auto Import, select the Add unambiguous imports on the fly checkbox, and apply the changes.

New Projects

Instructions for each new project

  • IntelliJ first project IMPORTANT INSTRUCTIONS

    • When you type a Project name, it should create a directory for the project. If you change the directory where you want to save the project, it might not automatically create a folder for the project, which can mess up things with GitHub. If that happens, if a folder name matching the project name doesn't show up after the folder name where you want to save the project, type it in. The Project location should be something like C:\Users\username\OneDrive - Florida Gulf Coast University\IdeaProjects\ProjectName

  • Create new project

      • Project location should be a folder that syncs to the cloud like OneDrive

      • Name projects with all lowercase letters using dashes for word separation, no spaces

      • Base package can be blank or io.github.username

New JavaFX Projects

  • If using Java 8 it is very easy.

    • Create New Project -> Java FX

    • See New Projects section for important name and location information

  • If using Java 11 it is not very easy, see GUI page.

Regular Use

Resources for regular reference as needed and taking your skill and knowledge to the next level

  • When you reopen an FX or Gradle project you need to import it.

    • Create from existing sources

    • Overwrite -> Yes, Next a bunch, Reuse iml file, Next, Finish

    • Expand src to Main, right click, Run Main.main()

  • When weird things are happening try File -> Invalidate Caches / Restart

  • Shortcuts / Text expansion

    • Ctrl+Alt+L format

    • sout Tab

  • Preparing for JavaFX Application Development (and other JavaFX Help) JetBrains

  • Help - tutorialspoint

  • IntelliJ Learn

  • IntelliJ Help

  • Version Control tutorialspoint

  • Diagrams

    • right click src or package -> Diagrams -> Class Diagrams (Ultimate only, UML plugin)

    • Diagrams from code, code from diagrams

  • To find JavaDoc comments in IntelliJ: View -> Quick Documentation or the corresponding keyboard shortcut

  • Right click, Go To -> Declaration

  • Introduction to the Standard Directory Layout

Troubleshooting

  • If you get an error when you try to add a class do File -> Restore Default Settings

GitHub Integration

Integrate with GitHub

Deployment

Create executable jar

  • The goal of deployment is to create an executable jar or exe file that will run your program outside of IntelliJ. There are many ways to deploy with and without IntelliJ.

  • First, check your project's out folder for an artifact folder with an executable jar file in it. If you already have one you don't need to do anything and can jump past the options below. If not, you will need to do one of the following:

    • No Maven or Gradle: use IntelliJ to create JAR artifact

      • IntelliJ Settings/Preferences | Project Structure | Artifacts

        • Click plus sign -> JAR -> From modules with dependencies -> Choose Main Class

        • extract to the target JAR should be selected

        • Apply, OK

        • Build | Build Artifact

public class Launcher {

public static void main(String[] args) {

Main.main(args);

}

}

      • Add this to build.gradle:

jar {

manifest {

attributes 'Main-Class': 'Launcher'

}

from {

configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }

}

}

      • Example

      • If your program contains a database, the first time you run the jar it will create a new database outside of the project. You can connect to the new database in IntelliJ to create tables. See the end of the Maven video.

      • More information

Dependencies

  • If your project has dependencies (like H2 jar) and you're not using Maven or Gradle

    • Modules | Dependencies, check box to export jar

Once you have the executable jar file

  • Double click jar file. If that doesn't work, run from the terminal with java -jar FileName.jar or create a .bat file

  • Run through web page (in theory)

    • Open html file. Copy the URL.

    • Open Java Control Panel Security tab, click Edit Site List. Click Add. Paste the URL. Click Ok. Click Continue. Click OK or Apply.