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