When studying Java Silver, I wanted to run Java in a state close to the actual development environment, so I set the environment so that Java code can be run from VS Code and iTerm.
When running Java without using the local environment, I used a site called dokojava. This site was recommended in the book "Introduction to Java for a refreshing understanding".
Develop by installing "Java Extension Pack" in Visual Stdio Code, referring to the site Create a Java (debugging) development environment with Visual Studio Code I set up the environment, but I couldn't master it, and after all, by installing OpenJDK, I was able to run Java locally.
However, wasn't the process of installing the "Java Extension Pack" on Visual Stdio Code necessary anyway? I leave it in the article because I think.
Also, OpenJDK is installed in the virtual environment of Ubuntu, but Java installed from the "Java Extension Pack" of Visual Stdio Code seems to be in the local environment.
Currently, Java in the local environment is "java version" 14.0.2 "" Java on ubuntu is "openjdk version" 1.8.0_265 "".
Is this bad ...
I set it by referring to the site Create a Java (debugging) development environment with Visual Studio Code.
-First, install "Java Extension Pack" in Visual Studio Code
-Open the settings from the gear mark at the bottom left and open "setting.json"
-Add Java settings to "setting.json"
"java.home": "/ Library / Java / JavaVirtualMachines / (installed JDK folder) / Contents / Home /"
And write.
Check the installed JDK folder by typing the "java -version" command in the terminal.
I installed open source Java called OpenJDK by referring to "Introduction to Java 8" of dot installation.
According to the documentation
$ sudo apt-get install openjdk-8-jre
When I tried to install with the command I was impatient with an error stating that the local version may be out of date.
$ sudo apt update
I upgraded it with a command and reinstalled it, and it worked.
javac (filename) .java
Compile with
java (filename)
Execute with.
In Visual Studio Code, the path from the root directory to the corresponding java file may be suggested as the package name. If you name the package accordingly, you will get a "package not found" error at compile time.
** * The directory that starts javac is the "starting point of the package"! ** **
With the above directory structure, if you start javac in the java_lessons directory
-The package name of "MyApp.java" is
com.dotinstall.myapp
-The package names of "AdminUser.java" and "User.java" are
com.dotinstall.myapp.model
Will be.
Command to launch the packaged one
javac com/dotinstall/myapp/MyApp.java
The path to the java file to compile corresponds to the package name. File with entry point (main method) to compile
java com/dotinstall/myapp/MyApp
Run on
-Compile commands
javac -d (output destination) (package name) / (class name) .java
-Specify the classpath of the class to be executed
java -cd (classpath) (package name)
Create a Java (debugging) development environment with Visual Studio Code