Configure java environment variables and Eclipse in Linux

Source: Internet
Author: User
In Linux, configure the java environment variables and Eclipse configurations-general Linux technology-Linux programming and kernel information. For more information, see the following. 1. Go to java.sun.com/j2se/1.4.2/download.html "> download a Linux Platform JDK,

It is recommended to download RPM in self-extracting file (j2sdk-1_4_2_06-linux-i586-rpm.bin) in RPM in self-extracting format );

2. Upload the file to a Linux server and run the following command in shell:

[Root @ LinuxServer rpm] # chmod 755 j2sdk-1_4_2_11-linux-i586-rpm.bin

[Root @ LinuxServer rpm] #./j2sdk-1_4_2_11-linux-i586-rpm.bin

There will be a piece of Sun Protocol, several times the Space key, when asked whether to agree, you can press yes.

Sun Microsystems, Inc.

Binary Code License Agreement

For

JAVATM 2 software development kit (J2SDK), STANDARD

EDITION, VERSION 1.4.2 _ X

...

Do you agree to the above license terms? [Yes or no] yes

Unpacking...

Checksumming...

0

0

Extracting...

UnZipSFX 5.40 of 28 November 1998, by Info-ZIP (Zip-Bugs@lists.wku.edu ).

Inflating: j2sdk-1_4_2_11-linux-i586.rpm

Done.

Note: If you run the unzip command directly to decompress the package, you can obtain an rpm package.

3. The program will automatically generate a j2sdk-1_4_2_11-linux-i586.rpm file, which is the main package, to install below;

[Root @ LinuxServer rpm] # rpm-ivh j2sdk-1_4_2_11-linux-i586.rpm

Preparing... ######################################## ### [100%]

1: j2sdk ####################################### #### [100%]

4. Set Environment Variables

Usually, you prefer to use the export command to directly set it in shell.

[Root @ LinuxServer rpm] # export JAVA_HOME =/usr/java/j2sdk1.4.2 _ 11

[Root @ LinuxServer rpm] # export CLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar

[Root @ LinuxServer rpm] # export PATH = $ PATH: $ JAVA_HOME/bin

Of course, this setting of environment variables takes effect only for the current shell. If you log on from another shell, you cannot use the variable you just set. So the best way is to modify the. bashrc file.

[Root @ LinuxServer rpm] # vi. bashrc

Set JAVA_HOME =/usr/java/j2sdk1.4.2 _ 11

Export JAVA_HOME

Set PATH = $ PATH: $ JAVA_HOME/bin

Export PATH

Set CLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar

Export CLASSPATH

Of course, you can also change the/etc/profile. However, this setting is not recommended because it will take effect for your shell and affect system security. Add the following at the end of the file:

Export JAVA_HOME =/usr/java/j2sdk1.4.2 _ 11

Export CLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar

Export PATH = $ PATH: $ JAVA_HOME/bin

Next, verify whether the variable settings take effect (#### Note: log out before verification, and then log on again );

[Root @ LinuxServer rpm] # echo $ JAVA_HOME

/Usr/java/j2sdk1.4.2 _ 11/

[Root @ LinuxServer rpm] # echo $ CLASSPATH

/Usr/java/j2sdk1.4.2 _ 11/lib/dt. jar:/usr/java/j2sdk1.4.2 _ 11/lib/tools. jar

[Root @ LinuxServer rpm] # echo $ PATH

/Usr/java/j2sdk1.4.2 _ 11/bin/:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbi

N:

/Usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin

[Root @ LinuxServer rpm] # JAVA-version

JAVA version "1.4.2 _ 11"

JAVA (TM) 2 Runtime Environment, Standard Edition (build 1.4.2 _ 11)

JAVA HotSpot (TM) Client VM (build 1.4.2 _ 11, mixed mode)

5. Set the environment to OK to see if JDK works normally. Let's write a test file test. java.

[Root @ LinuxServer rpm] # vi test. java

Class test

{

Public static void main (String [] args)

{

System. out. println ("Hello World! ");

}

}

Save and exit. Compile and execute the command below;

[Root @ LinuxServer text] # javac test. java

[Root @ LinuxServer text] # JAVA test

Hello World!

Working properly.


6. To allow a user to run java commands, modify the bash initialization file.

For example, to grant longware the permission to run java commands,

[Root @ LinuxServer root] # vi/home/longware/. bashrc

Set JAVA_HOME =/usr/java/j2sdk1.4.2 _ 11

Export JAVA_HOME

Set PATH = $ PATH: $ JAVA_HOME/bin

Export PATH

Set CLASSPATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar

Export CLASSPATH

7. Now, JDK installation on Linux is complete. Install eclipse-sdk-3.0-linux-gtk.zip at www.eclipse.org to download a eclipse3.0. unzip eclipse-sdk-3.0-linux-gtk.zip to/opt.

8. Write a script to start eclipse

#! /Bin/bash

#

# Execute eclipse 3

#

Export JAVA_HOME =/usr/java/j2sdk1.4.2 _ 11

Export CLASSPATH =/usr/java/j2sdk1.4.2 _ 11/lib

/Opt/eclipse-vm/usr/java/j2sdk1.4.2 _ 06/bin/java-data/home/chenzhe/wo

Rkspace &

#-Vm parameters are used to specify which jvm is used to execute Eclipse,

# The-date parameter is used to specify the Eclipse data directory.

Specify that it exists in the workspace directory under the user root directory (/home/chenzhe /)

Save the script to/usr/local/bin, called eclipse, and assign 755 permissions to eclipse.

9. Create a starter on the desktop. Select an icon and set the path to/opt/eclipse./opt/eclipse/icon. xpm is the eclipse icon.

10. Double-click the icon or enter eclipse on the terminal!
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.