"Java" Java program packaged as a jar package running on Linux

Source: Internet
Author: User

When you need to run Java programs that are developed on Windows for Linux, it is necessary that the Java program is packaged into a jar package and uploaded to Linux to run.

the 1.Java program is packaged into a runnable jar package with MyEclipse

(1) in the MyEclipse selected items need to be packaged, right click, select: Export ... As shown in the following:




(2) then select: Java-->runnable JAR file in the pop-up window, then click: Next as shown:



(3) then select the program to be packaged and save the place, then click on: Finish as shown:



This allows the Java program to be packaged as a runnable jar package and can be copied to Linux to run.


2. Packaged jar packages run on Linux

Of course, Linux already has a Java operating environment first. Then you just need to enter it at the command line: Java-jar Test.jar

Can run, where Test.jar is the jar package of the previously packaged Java program.


3.Java Program receives command-line arguments

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

The command-line arguments of Java are the parameters of the main function in the program: string[] args, where the args array is an array of all the command-line arguments that need to be received.

When you run a program in MyEclipse, you need to enter the command line arguments you want to receive, in the following steps:

(1) Click the Run option in the menu bar and select: Run configurations ... or Debug configurations ... as shown in:



(2) Then in the pop-up window, click: Arguments option, and then enter the command line parameters to receive in program Arguments, the middle of multiple parameters separated by a space, click Apply, click Run or Debug, as shown in:


After the program is successfully run, and then packaged into a runnable jar package as described in the previous method, and then run on Linux,

Input command: Java-jar test.jar val1 val2, you can run the program.

Where Val1 and Val2 are the command line arguments that the program needs to receive.



I hope we have some help, thank you.







"Java" Java program packaged as a jar package running on Linux

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.