[Java] Java program is packaged into a jar package and runs on Linux. jarlinux

Source: Internet
Author: User

[Java] Java program is packaged into a jar package and runs on Linux. jarlinux

When you need to use the Java program developed on Windows to run on Linux, You need to package the Java program into a jar package and upload it to Linux for running.

1. Use MyEclipse to package Java programs into runnable jar packages.

(1) In MyEclipse, right-click the project to be packaged and choose Export... As shown in:




(2) Select Java --> Runnable JAR file in the pop-up window, and click: Next, as shown in:



(3) Select the program to be packaged and saved, and click Finish, as shown in:



In this way, the Java program is packaged into a runable jar package and can be copied to Linux for running.


2. the packaged jar package runs on Linux

Of course, first of all, there is a Java Runtime Environment on Linux. Then, enter java-jar test. jar in the command line.

You can run it. test. jar is the jar package of the previously packaged Java program.


3. How the Java program receives command line parameters

If you need to receive command line parameters when running on Linux, You need to modify the program in the source Java program so that it can receive command line parameters.

The Java command line parameter is the main function parameter in the program: String [] args. The args array is the array of all command line parameters to be received.

When running a program in MyEclipse, you must enter the command line parameters to receive. The steps are as follows:

(1) Click "Run" in the menu bar and select "Run events..." or "Debug events...", as shown in:



(2) Click the Arguments option in the pop-up window, and enter the command line parameters to be received in Program arguments. Separate multiple parameters with spaces. Click Apply, click Run or Debug, as shown in:


After the program runs successfully, package the program into a runable jar package according to the preceding method, and then run the package on Linux,

Run java-jar test. jar val1 val2 to run the program.

Val1 and val2 are the command line parameters that the program needs to receive.



Thank you for your help.







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.