Ubuntu VSCode
--Java, Maven, Intellij installation --vscode settings --Execution confirmation --Error handling
Please note that apt update, java installation and java version check are performed together below.
Java
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)
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
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
sudo add-apt-repository ppa:mmk2410/intellij-idea-community
sudo apt update
sudo apt install intellij-idea-community
Search with intellij and click install
VSCode
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
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
java.home You will be able to run JAVA on VS Code.
maven.executable.path Maven commands can now be executed on VS Code.
code-runner.runInTerminal Enables CodeRunner input / output with terminal.
~~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,
]
--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!");
}
}
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
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 Posts