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:

Copy a File from Local To Remote Server

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 user@remotehost.com:/home/destination

Run a Jar File on a Remote Server using ssh

  1. Open terminal and ssh to your remote server:
  2. sudo ssh -i "your-remote-server.pem" user@ec2-4-3-2-1.us-east-1.compute.amazonaws.com
  3. Here's a commnd to run the copied jar file in dev environment using the following command:
  4. java -Dspring.profiles.active=dev -jar my-file.jar

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