Ubuntu 18.04. 1 build Java environment and HelloWorld

1、 Build Java environment

System environment

1. Download JDK

Official website address: http://www.oracle.com/technetwork/java/javase/downloads/index.html

Select the corresponding version, click JDK, enter the download page, and select the Linux x64 version with the suffix "XXX. Tar. GZ".

2. Unzip the JDK package

Find the compressed package in the download, double-click the file, and drag the file in the directory to the "/ home / Stone / Java /" directory (equivalent to manual decompression). The "/ home / Stone / Java /" file is the directory of my own computer, and users can store it according to their own directory structure, as shown in the following figure:

Don't ask me why Ubuntu is so like a MAC system. I won't tell you that I install a Mac theme.

3. Configure global system variables

Open the command line tool and enter the command:

This command modifies the global variable file and pastes the following code at the end of the file:

export JAVA_HOME=/home/stone/java/jdk1.8.0_181  
export JRE_HOME=${JAVA_HOME}/jre  
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib  

export PATH=${JAVA_HOME}/bin:$PATH

Note: "home / Stone / Java / jdk1.8.0_181" is my own JDK directory. Users need to change it to their own directory.

The configuration is as follows:

After copying the code, save and leave.

4. Update the configuration and test the Java installation

Enter command:

To make the global file effective, this is the Java environment. Even if the installation is successful, next, we enter the command:

Check the Java version to confirm whether the Java installation is normal, as shown in the following figure:

If the above java version information appears, the installation is successful.

2、 Create a Java (Maven) project

1. Install the idea open tool

To create a java project, first we need to go to the official website, now the idea development tool, address: https://www.jetbrains.com/idea/download/#section=linux

The download and installation process is relatively simple. We won't introduce it too much here. For installation, you only need to enter the bin directory of idea and execute the command line command:

The installation is complete.

2. Crack idea

It only takes 3 steps to crack the idea. Of course, if you have the ability, I suggest you buy a genuine version.

3. Create Java Maven project

a). New project

Click file = > New = > Project.. = > Click the "Maven" option on the left, as shown below:

Click next

b). Fill in the project information and complete the creation

Then keep clicking "next" to complete the creation of the project.

c). New Java class

In Src / main / Java, add the package name "com. Hello. Java" and application Java class, add the main method, output "Hello, Lao Wang", click the debug button to run the project, as shown in the figure above, run successfully, output the print information, and the whole project will be created.

d). Maven directory structure description

Maven project, the main part, is shown in the figure below:

The important part is the red part of the chart above, in which:

e). Add reference jar package

As the core function of maven, it is convenient to reference the jar package, so that we don't have to find the jar package on the Internet, just in the root directory of the project POM After XML configuration, the jar package will be automatically downloaded. The example configuration is as follows:

<dependency>
    <groupId>ch.qos.logback</groupId>
    <artifactId>logback-classic</artifactId>
    <version>1.1.1</version>
</dependency>

Find the jar package that Maven project depends on and visit: http://mvnrepository.com/ Enter the name to facilitate search and copy the code.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>