Copy and Run a Java or a Spring Boot Jar File on a Remote AWS Server via Terminal

Follow the steps below to copy a Java or a Spring Boot jar file from your local machine to a remote EC2 Linux/Ubuntu server and run the jar file via terminal:

  1. Copy a File from Local To Remote Server:
  2. Open a terminal on your local machine and execute the following scp (secure copy) command to copy a file from your local host to a remote EC2 server:

    sudo scp -i "your-remote-server.pem" my-file.jar

  3. Run a Jar File on a Remote Server using ssh:
    • Open terminal and ssh to your remote server:
    • sudo ssh -i "your-remote-server.pem"

    • Here's a commnd to run the copied jar file in dev environment using the following command:
    • java -jar my-file.jar

      You can replace 'dev' and execute the application within an alternate environment as per your specific needs.