Article Title: let Java Pentium on Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Author: Yang Peng
Linux is sweeping the global network operating system market in a free spirit, and Java is rapidly occupying the high-end software field with its open and advanced architecture. By combining the two, you can implement Java Advanced applications at a low cost in Linux, and give full play to the advantages of Java in a free and efficient environment. Therefore, the combination of the two is complementary in terms of cost and performance. For example, the recommended implementation of popular server-side script JSP is Tomcat on Linux, and the combination with Jboss is an excellent EJB platform.
However, the reason why Linux is not widely used in desktop applications and other fields is that complicated software installation and setup is an important reason. To implement Java programming in Linux, the general environment settings may be prohibitive for Windows users. In fact, many problems can be solved only by simple settings.
Next, I will take Red Hat Linux 7.2 as an example to talk about the JDK/JRE environment configuration process. Since JDK1.x generally comes with JRE (Java Runtime Environment, Java Runtime Environment), it is not discussed separately without additional installation.
We recommend that you download JDK packages in RPM format if you are not familiar with Linux. You only need one command to complete the installation:
Rpm-ivh j2sdk-1_x_x-linux.rpm
By default, the installation path is/usr/java/jdk1.x, and the corresponding JRE directory is/usr/java/jdk1.x/jre. The installation of the RPM package is only the beginning. to smoothly compile and run the Java program, you must set the following path.
JAVA_HOME: indicates the JDK installation path, for example,/usr/java/jdk1.x.
JRE_HOME: corresponds to JAVA_HOME, and the JRE directory under it, such as/usr/java/jdk1.x/jre.
PATH: similar to the Path in Windows, it is the execution PATH of Java, Javac, and other programs. it should point to the BIN directory under JDK and JRE, but should not overwrite the original Path, run the following command:
LD_ASSUME_KERNEL: After the installation is complete, the most common problem is to stop responding when Java or Javac is executed. Switch to another console and you can see several processes with the same name, one of which is Defunct. This is caused by version conflicts between databases. in this case, you need to output this variable and specify the version.
Export LD_ASSUME_KERNEL = 2.2.5
CLASSPATH: this is a very important environment variable used to specify the location of a non-core Java library, that is, whether to set it does not affect the use of the Java core library. Usually:
/Usr/java/jdk1.x/lib/tools. jar:/usr/java/jdk1.x/lib/dt. jar :.
Pay special attention to the last dot, which is a problem that beginners can easily encounter. If we set the ClassPath variable without this dot, the system will prompt NoClassFoundError when executing the simplest HelloWorld program... Error. The reason is that Java looks for classes based on ClassPath (don't forget that Java programs are class-based), but Linux does not automatically search for the current directory, the result is of course the current class cannot be found (if ClassPath is not set, it can be executed, because when the variable cannot be found, the default value is the current path ). The dot is used to add the current directory to the class search path.
After the above work is completed, most Java programs should be able to run normally. If the problem persists, it may be that some libraries in the system are not compatible and can be addressed by installing the Compat-c library, including compat-glibc-xx.x.x.rpm, compat-libs-xx.x.x.rpm, and compat-egcs-xx.x.x.rpm, these packages can be found on Red Hat 7.2. After the installation is complete, remember to run the/usr/i386-glibc.../bin/istrap... env. sh script to set the environment.
In addition, some problems may occur due to some connection symbols, such as the libstdc ++-libc6.1-1. so.2 Library in Java/usr/lib. In fact, different versions may only point to libstdc ++-2 connections, or to libstdc ++-3 connections. At this time, you can follow the system prompts to find no library, you need to refer to the relevant connection under the Directory (because it may only be the difference between versions), manually establish a connection to the corresponding Library.
In this way, all preparations are completed. Finally, we recommend that you add the preceding variable settings to/etc/profile so that they can be automatically executed at each start.
Through the above efforts, I believe that your Java program can run smoothly on Linux.
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.