First, build a Java environment system environment
- Ubuntu 18.04.1
- JDK 8
- Idea 2018.2
1. Download the JDK
Website address: http://www.oracle.com/technetwork/java/javase/downloads/index.html
Select the appropriate version, click JDK, go to the download page and select the "Linux x64" version of the Liunx compression package with the suffix "xxx.tar.gz".
2. Unzip the JDK package
Find the compressed package in the download, double-click the file, drag the files in the directory into the "/home/stone/java/" directory (rather with the manual decompression), "/home/stone/java/" file for my own computer directory, the user can be stored according to their own directory structure, as shown:
Don't ask me how Ubuntu is so like a Mac system, I'm not going to tell you that I'm pretending to be a Mac theme.
3. Configuring Global System Variables
Open the Command line tool and enter the command:
$sudo gedit ~/.BASHRC
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: where "home/stone/java/jdk1.8.0_181" is the JDK directory I have stored for myself, the user needs to change to their own directory.
Configuration such as:
After you copy the code, save and leave.
4. Update the configuration, test the Java installation
Enter the command:
sudo source ~/.BASHRC
Make the global file take effect, to this Java environment even if the installation is successful, then we enter the command:
Java-version
Check the Java version to see if the Java installation is working properly, such as:
The installation is successful if the Java version information appears.
Ii. Creating a Java (Maven) Project 1. Install Idea Open Tool
Need to create Java project, first we go to official website now Idea development tool, address: https://www.jetbrains.com/idea/download/#section =linux
The process of downloading and installing is relatively simple, we do not introduce too much here, install only need to go into idea's Bin directory to execute command line command:
> ./idea.sh> > ```
To complete the installation.
2. Break idea
It only takes 3 steps to hack idea, and of course if you have the ability to suggest a genuine purchase.
- Go to website: http://idea.lanyus.com/Click to get registration code
-
- "0.0.0.0 account.jetbrains.com" added to the Hosts file
-
- Fill out the verification code obtained on the site into the idea activation box and click Confirm
3. Create a MAVEN project for Java a). New project
Click File = + New + Project. + click on the "Maven" option on the left, such as:
Click Next.
b). Fill in the project information and complete the creation
- GroupID group ID, can be repeated
-
-
- Version: Project release number
Then always click on "Next" to complete the project creation.
c). New Java class
In Src/main/java, increase the package name "Com.hello.java", add the Application.java class, add the main method, output "Hello, Lao Wang", click the Debug button to run the project, such as run successfully, output printing information, This entire project was created.
D). MAVEN Directory Structure description
The MAVEN project, as shown in the main section, is as follows:
The important part is the red part of the table, where:
- Java directory for Java source code in this directory
-
- Resources This directory is a static resource file and a template file
-
- Pom.xml This file is all dependent jar packages for the current project
-
- External Libraries for all referenced jar packages generated based on Pom.xml
e). Add a reference jar package
As a core feature of Maven, it is easy to refer to the jar package, so that we can not find the jar on the net, we need to download the jar package automatically after the project root pom.xml configuration, the sample configuration is as follows:
<dependency><groupId>ch.qos.logback</groupId><artifactId>logback-classic</artifactId><version>1.1.1</version></dependency>
- GroupId: Project name of the required jar package
- Artifactid: module Name of the required jar package
- Version: The build number of the required jar package
Find the jar package that the MAVEN project relies on, Access: http://mvnrepository.com/Enter a name to easily find, copy code.
Ubuntu 18.04.1 build Java environment and HelloWorld