[Java] Build Java development environment on Ubuntu & check execution

environment

Ubuntu VSCode

things to do

--Java, Maven, Intellij installation --vscode settings --Execution confirmation --Error handling

reference

This is very helpful!

Installation

Please note that apt update, java installation and java version check are performed together below.

Java

Installation

sudo apt update && sudo apt install default-jdk && java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode)

JAVA_HOME setting

Since the installation location of jdk is in / usr / lib / jvm /, add this path to the 〇〇rc file.

~/.〇〇rc file


# ------------------------------------------------------------------
# java
# ------------------------------------------------------------------
export JAVA_HOME=/usr/lib/jvm/java-version-xxx-jdk
export PATH="$PATH:$JAVA_HOME/bin"

Maven

Installation

sudo apt update && apt install maven && mvn -version
Apache Maven 3.6.0
Maven home: /usr/share/maven
Java version: 11.0.6, vendor: Ubuntu, runtime: /usr/lib/jvm/java-11-openjdk-amd64
Default locale: ja_JP, platform encoding: UTF-8
OS name: "linux", version: "4.15.0-54-generic", arch: "amd64", family: "

IntelliJ IDEA Community Edition

Installation

① From PPA
sudo add-apt-repository ppa:mmk2410/intellij-idea-community
sudo apt update
sudo apt install intellij-idea-community
② From the software center

Search with intellij and click install

VSCode

Installation

wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main"
sudo apt update && sudo apt install code

VS Code settings

Extensions

Java Extension Pack ――Put this in without thinking. --The minimum required tools for Java development will be installed together. https://marketplace.visualstudio.com/items?itemName=vscjava.vscode-java-pack

Code Runer

--You can debug the selected range. --You can run Code Runner with Ctrl + Alt + N.

https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner

settings.json

~~code-runner.executorMap code runner Sets the run-time command. With the default settings, the target file is considered to have no fileNameWithoutExt extension, so an error (java.lang.NoClassDefFoundError) may occur depending on where the debug is executed. This can be avoided by using $ fileName ~~

Find out the execution path of maven


which mvn
> /usr/bin/mvn

settings.json


[
  // Java
  "java.home":"/usr/lib/jvm/java-version-xxx-jdk",

  // Maven
  "maven.executable.path": "/usr/bin/mvn",

  // Code Runner
  "code-runner.runInTerminal": true,
]

Execution confirmation

--Use VS Code. --Create an appropriate directory and create a HelloWorld.java file. --The part where the main method is located is debugged.

Main method public static void main(String[] args) Be sure to describe this.

~/java_lessons/hello_java/HelloWorld.java


public class HelloWorld {
	public static void main(String[] args) {
		System.out.println("Hello World!");
	}
}

Run

Either of the following can be executed. Compile & run.

--Run with Code Runner (Ctrl + Alt + N)

[Done] exited with code=1 in 1.227 seconds

[Running] cd "/home/user/java_lessons/hello_java/" && javac HelloWorld.java && java HelloWorld

Hello World!

Without the main method It will be as follows.

error:The main method cannot be found in class HelloWorld. Define the main method as follows:
   public static void main(String[] args

Error example

Remedy etc.

The compiler compliance specified is x.x but a JRE x.y is used

Match the corresponding number in .settings/org.eclipse.jdt.core.prefs to the JRE version

eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.targetPlatform= x.y
org.eclipse.jdt.core.compiler.compliance= x.y
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.processAnnotations=disabled
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source= x.y

Recommended

You can try it out!

Recommended Posts

[Java] Build Java development environment on Ubuntu & check execution
Build a Java development environment on Mac
Build Java 8 development environment on AWS Cloud9
Build Java development environment with VS Code on Mac
Build Java development environment (for Mac)
Build a XAMPP environment on Ubuntu
Build Unity development environment on docker
Install Java development environment on Mac
Java development environment
[Ruby] Building a Ruby development environment on Ubuntu
Build OpenCV with Java Wrapper on Ubuntu 18.04
Build an Ultra96v2 development environment on Docker 1
Try to build Java8 environment on Amazon Linux2
Build and install Wireshark Development Release (3.3.1) on Ubuntu
Java development environment memo
Build Apache / Tomcat development environment on Cent OS 7
java development environment construction
Build a development environment for Docker, java, vscode
Build a Java runtime environment on Sakura VPS
How to build a Pytorch environment on Ubuntu
Build Zabbix on Ubuntu 20.04
Build a Java development environment with VS Code
Create a Java development environment using jenv on Mac
Build Ubuntu 20.04 LTS desktop environment on Raspberry Pi 4 (+ Japanese)
Java development environment construction on Mac-JDK Install (2020 preservation version)
Build Java development environment with WSL2 Docker VS Code
How to build Java development environment with VS Code
[Environment construction] Build a Java development environment with VS Code!
Try to build a Java development environment using Docker
Build Java program development environment with Visual Studio Code
Java + Spring development environment construction with VirtualBox + Ubuntu (Xfce4)
Install OpenJDK7 (JAVA) on ubuntu 14.04
Oracle Java 8 on Docker Ubuntu
Install Java on WSL Ubuntu 18.04
Java development environment (Mac, Eclipse)
Ubuntu on Windows build speed
Run java applet on ubuntu
Install Ubuntu 20.04 in virtual box on windows10 and build a development environment using docker
Build mate desktop environment on ec2 with terraform (Ubuntu 20.04LTS)
Build WebAPP development environment with Java + Spring with Visual Studio Code
[Java development environment construction] Install OpenJDK 11 (Java 11) on macOS with Homebrew.
[Eclipse Java] Development environment setting memo
Execution environment test after Java installation
Prepare Java development environment with Atom
Build the latest Samba 4 on Ubuntu 20.04
Play Framework 2.6 (Java) development environment creation
About the current development environment (Java 8)
Build jooby development environment with Eclipse
Enable Java 8 and Java 11 SDKs on Ubuntu
Java cannot be installed on Ubuntu 13.04
Java development environment (Mac, VS Code)
How to build vim on Ubuntu 20.04
Build ffmpeg 4.3.1 on Ubuntu for Windows
Build a development environment where Ruby on Rails breakpoints work on Windows
Notes on building Kotlin development environment and migrating from Java to Kotlin
[ev3 × Java] leJOS development environment construction (Eclipse on Mac OSX / bluetooth)
Create a development environment for Ruby 3.0.0 and Rails 6.1.0 on Ubuntu 20.04.1 LTS
Steps to build a Ruby on Rails development environment with Vagrant
Build debug environment on container --Build local development environment for Rails tutorial with Docker-
How to check Java installed on Mac
Create Spring Boot development environment on Vagrant