'Getting file not found for a jar while trying to run springboot app in AWS ec2

I have a spring boot jar that works fine in my local and even on GCP but when I uploaded this jar to ec2-user location and try to run using java -jar , I am getting error like below and its happening for multiple jar not just one.

java.io.FileNotFoundException: /home/ec2-user/HikariCP-4.0.0.jar (No such file or directory)

This is how added it as dependency in pom.xml

    <dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>4.0.0</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>

Has anyone faced issue like this?



Solution 1:[1]

Adding below in my build plugin helped to resolve the issue.

<plugin>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-maven-plugin</artifactId>
  <executions>
    <execution>
      <goals>
        <goal>repackage</goal>
      </goals>
      <configuration>
        <classifier>spring-boot</classifier>
        <mainClass>mainclass</mainClass>
      </configuration>
    </execution>
  </executions>
</plugin>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 vs14