Home Setup JDK, maven, Java Spring Boot app with IntelliJ Idea on Ubuntu / Linux
Post
Cancel

Setup JDK, maven, Java Spring Boot app with IntelliJ Idea on Ubuntu / Linux

This article will help you to setup JDK, maven, IntelliJ idea & create a new Java Spring Boot app on Ubuntu / Linux

Setup Java

  • Install OpenJDK from https://adoptium.net/ & Download Linux tar file
    • Check your architecture version by running:
      1
      
      lscpu
      

      If Architecture: x86_64, this means you are on x64

  • Untar / unzip the file which extracts to jdk-17.0.6+10 folder:
    1
    
    tar -zxvf OpenJDK17U-jdk_x64_linux_hotspot_17.0.6_10.tar.gz
    
    1
    
    chmod +x jdk-17.0.6+10 
    
  • Set JAVA_HOME & PATH variables:
    1
    
    vim ~/.bashrc
    
    1
    2
    
    export JAVA_HOME=/home/abhi/Downloads/jdk-17.0.6+10 
    export PATH=${PATH}:${JAVA_HOME}/bin 
    

    Append these variables to .bashrc file, save and now reboot terminal & run below java cmd to test setup

    1
    
    java --version
    

    successfull output:

    1
    2
    3
    
      openjdk 17.0.6 2023-01-17
      OpenJDK Runtime Environment Temurin-17.0.6+10 (build 17.0.6+10)
      OpenJDK 64-Bit Server VM Temurin-17.0.6+10 (build 17.0.6+10, mixed mode, sharing)
    

Setup Maven

  • Download maven from https://maven.apache.org/download.cgi as Binary tar.gz archive file: apache-maven-3.8.7-bin.tar.gz

  • Untar / unzip the file which extracts to apache-maven-3.8.7 folder:
    1
    
    tar -zxvf apache-maven-3.8.7-bin.tar.gz 
    
    1
    
    chmod +x apache-maven-3.8.7 
    
  • Set M2_HOME & PATH variables:
    1
    
    vim ~/.bashrc 
    
    1
    2
    
    export M2_HOME=/home/abhi/Downloads/apache-maven-3.8.7 
    export PATH=${PATH}:${M2_HOME}/bin
    

    Append these variables to .bashrc file, save and now reboot terminal & run below mvn cmd to test setup

    1
    
    mvn --version
    

    successfull output:

    1
    2
    3
    4
    5
    
      Apache Maven 3.8.7 (b89d5959fcde851dcb1c8946a785a163f14e1e29)
      Maven home: /home/abhi/Downloads/apache-maven-3.8.7
      Java version: 17.0.6, vendor: Eclipse Adoptium, runtime: /home/abhi/Downloads/jdk-17.0.6+10
      Default locale: en_IN, platform encoding: UTF-8
      OS name: "linux", version: "5.15.0-57-generic", arch: "amd64", family: "unix"
    

Setup IntelliJ Idea

  • Download Community edition (free) from https://www.jetbrains.com/idea/download/#section=linux as ideaIC-2022.3.1.tar.gz

  • Untar / unzip the file which extracts to idea-IC-223.8214.52 folder:
    1
    
    tar -zxvf ideaIC-2022.3.1.tar.gz 
    
  • Run IntelliJ installer, which will give you a wizard to install IntelliJ & run it:
    1
    2
    
    cd idea-IC-223.8214.52/bin
    ./idea.sh
    
  • Enable IntelliJ Idea to run from terminal or desktop: Open Intellij IDE: Open Intellij IDE
    • create command-line runner: ‘Tools’ menu> Create Command-line Launcher
    • create a desktop entry, ‘Tools’ menu > Create Desktop Entry

Create Java spring boot app

  • Goto spring initlalizer: https://start.spring.io/ & download maven/jar project (demo.zip) as shown in below screenshot: spring initializer

  • Unzip zip file & open it with IntelliJ idea:
    1
    2
    3
    
    unzip demo.zip
    cd demo
    idea . 
    
  • Tell IntelliJ about your JDK & maven paths (1 time setup):
    • Set JDK path: IntelliJ -> ‘File’ menu -> Project Structure -> Project (as shown below): intellij jdk setup
    • Set Maven home: IntelliJ -> ‘File’ menu -> Settings -> Build, Execution, Deployment -> Build Tools -> Maven(as shown below): intellij maven setup

Note: You may have to click ‘Reload All Maven Projects’ button on right hand side Maven panel, if you are not getting any intelli-sense in IDE or you get ‘Java file outside of source root intelliJ’ when you hover over Java files. This should resolve the issue.

  • Now run your spring boot app from IntelliJ IDE’s by right-clicking on DemoApplication file & selecting Run or from IDE terminal:
    1
    
    mvn spring-boot:run 
    
  • This will compile & run our spring boot app. Now open browser & navigate to http://localhost:8080/actuator (see below): intellij spring boot run

Note: JDK/maven/Intellij IDE versions may vary in future or you might be using a different distro of Linux, but this guide would still be valid.

This post is licensed under CC BY 4.0 by the author.

AWS re:Invent 2022 Keynote by Swami Sivasubramanian

Setup Dotnet, ASP.NET app with VS Code on Ubuntu / Linux

Comments powered by Disqus.