Home >Java >javaTutorial >How to execute java program under Linux

How to execute java program under Linux

王林
王林forward
2023-05-25 23:01:042207browse

If you want to run a java program on ubuntu, you can package the java program after successfully compiling it, and then use the command to execute the jar file on ubuntu

The specific operations are as follows:

1. On windows Use eclipse to compile the java project. After compilation, export it to a runnable jar file

For example, here the test2 file in the test project is exported as the mytest2.jar file

How to execute java program under Linux

How to execute java program under Linux

2. Installation of java environment on ubuntu

①jdk official website http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151. html download jdk used on linux

How to execute java program under Linux

②eclipse official website http://www.eclipse.org/downloads/packages/eclipse-ide-java-developers/heliossr1/download linux eclipse used on

How to execute java program under Linux

③Upload jdk and eclipse to the linux server and decompress it, and then configure the java environment variables (the decompression directory of eg.jdk is /home/test)

Configuration method: edit the /etc/profile file and add the following content (Note: colon in Linux: used to separate paths, dot. indicates the current directory)

export java_home=/home/test /jdk1.8.0_65

export path=$java_home/bin:$path

export classpath=.:$java_home/lib/dt.jar:$java_home/lib/tools.jar

Save the file after editing is completed

④To make the configuration take effect, command source /etc/profile

⑤To test whether the environment variables are configured successfully, command java -version

Display the jdk version, which means the java environment variable is configured successfully

3. Execute the jar file exported by the java project on ubuntu

Command: java -jar mytest2.jar

The above is the detailed content of How to execute java program under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete