The recent initial contact with Linux, feeling very fresh. What I've done before in Windows is also thought to be implemented in a Linux environment. Just in Java, I think since Java can be run under the DOS operation of Windows, is it possible to compile and execute under Linux terminal? Curiosity is the best teacher, and the rich resources on the Internet help me to realize this operation quickly. The specific implementation process is as follows:
To compile and execute Java code, you first need to have Java-enabled system programs, so-called Jdk,java Development Kit is doing this. JDK is a must for compiling and executing Java code, whether it is under Windows or Linux. (for the differences between JDK and JRE, see Blog:). The JDK shields the programmer from the differences between the two systems, allowing Java to implement "compile everywhere". JDK package, can be downloaded from the official website, according to different systems to download different installation packages. The installation method, also depending on the Linux version is slightly different, I am using the Redhat Linux (RHEL 6) system, download the corresponding. rpm file, like installing other software installation can be:
RPM-IVH jdk_8u25.rpm
Use other systems, such as Ubuntu, to download. tar.gz Compression Package for installation, many online information, not to repeat.
Install the JDK so we can copy the code from Windows to Linux. Here we do not directly copy the. Java code into the destination directory, but instead the Mr. into the jar package, and then the transfer.
Here we use eclipse to do this. (What is the relationship between Eclipse and JDK?) See blog:) under Eclipse to export the project source code into a jar package, you can select the project right-click->export->jar. Generate the required 1.jar, and then prepare additional jar packages, such as the usual Lucene, Mysql-connecor jar packages (which can also be made into a package), and copy the packages to the same directory in Linux (or upload to a Linux server). In addition, the main class file of Java code (containing the main function, such as Main.java) is also copied to the same directory
Perform. The first step is to execute the JAVAC and generate the. class file. The format is as follows:
javac-cp/home/username/. /1. jar:/home.username/. /2. jar:/home.username/. /3. Jar Main.java
This will run the Java program.
Running Java projects under Linux