Notes on Ubuntu building Java development environment

  • 2020-04-01 03:42:49
  • OfStack

Did not write the program in Java, as a Java novice, before writing the first Hello, world program, first build the Java development environment in Ubuntu.

JDK installation

Ok, I choose JDK1.6, is it a little out?

1, download JDK1.6, you can go to the official website to download, download please see their own version of the system, remember to download the corresponding version.
(link: http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase6-419409.html#jdk-6u41-oth-JPR)

2. Place the downloaded file in the /usr/lib-/java directory (need to manually create the Java directory) and modify the executable permissions of the file, such as chmod 777 jdk-6u41-linux-x64.bin
PS: if you are prompted that you have a Java file and cannot create Java, you can name the directory java1.6.

3. Installation file, sudo./jdk-6u41-linux-x64.bin

4. After the installation, you need to configure the system environment sudo vi /etc/environment, or configure the user environment variable vi /home/username/.bashrc, set up the JAVAHOME,CLASSPATH, and modify the PATH variable
As I set:


JAVA_HOME= " /usr/lib/java1.6/jdk1.6.0_41 "
PATH= " /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/lib/java1.6/jdk1.6.0_41/bin:/usr/lib/java1.6/jdk1.6.0_41/jre/bin "
CLASSPATH= " /usr/lib/java1.6/jdk1.6.0_41/lib:/usr/lib/java1.6/jdk1.6.0_41/jre/lib "

5. Execute the command to make the configuration take effect. Source /etc/environment(source /home/username/.bashrc)
6. Verify whether the installation is completed, use java-version or use javac directly, and see whether it takes effect or not.
7. If it's not working yet, it's likely that ubuntu already has a default JDK, such as openjdk, so in order to use our installed JDK by default, we need to do the following.

sudo update-alternatives � install /usr/bin/java java /usr/lib/java/jdk1.6.0_41/bin/java 300
sudo update-alternatives � install /usr/bin/javac javac /usr/lib/java/jdk1.6.0_41/bin/javac 300

This step adds the JDK we installed to the Java menu.
Then execute:

update-alternatives � config java

Two, MyEclipse installation

Installation package download address: (link: http://www.my-eclipse.cn/history.html)
Once the download is complete, modify permissions are executed directly to install.

The first Hello world program

1) create a new Java project named HelloWorld
2) create a new package named com.cricode
3) create a new SayHello class in the package com. Cricode, as follows:


package com.cricode;
 
public class SayHello {
 public static void main(String[] args){
  System.out.println("Hello,world");
 }
}

 
Run result: Hello,world

At this point, the Java development environment on Linux is installed.


Related articles: