Running Java projects under Linux

Source: Internet
Author: User

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:

    • Installing the JDK

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.

    • Generate Jar File

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
    • Compile execution
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

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.