Open DevShivmohan opened 1 year ago
mvn spring-boot:run &
commandthen run command with sudo like this sudo mvn spring-boot:run &
then this issue has been fixed.
private void killProcessViaPort(){
try {
String pid=null;
Process process=Runtime.getRuntime().exec("netstat -ltnup | grep ':8080'");
var scanner=new Scanner(process.getInputStream());
while (scanner.hasNext()){
var readline=scanner.nextLine();
System.out.println(readline);
if(readline.contains(":8080")){
StringBuilder stringBuilder=new StringBuilder();
for(char ch:readline.substring(readline.indexOf("LISTEN "),readline.lastIndexOf("/java")).toCharArray())
if((""+ch).matches("[0-9]+"))
stringBuilder.append(ch);
pid=stringBuilder.toString();
scanner.close();
break;
}
}
log.info("killing process with PID "+pid);
if(pid!=null && !pid.isBlank()){
process=Runtime.getRuntime().exec("kill -SIGKILL "+pid);
process.waitFor();
log.info("Process killed");
}
}catch (Exception e){
e.printStackTrace();
}
}
Clone a repo onto the server if not available [Clone it inside a new folder] git clone
<repo-url>
Clone a specific branch
git clone -b <branch-name> <repo-url>
Pulling the updated code on the remote server
git pull
overwrite local conflicting changes made, before pulling
git checkout <file-path-to-overwrite>
To stop a service on a particular port
sudo netstat -tulpn | grep LISTEN
kill -SIGKILL <PID>
To start a spring-boot application
mvn spring-boot:run &
Press: control + (A+D)
screen gradle bootRun
Alternative approach to start spring-boot application execute the below command on the root directory of project, this will create the required jar in the /target folder
mvn clean install
execute the below command on the root directory of project, this will start the applicationjava -jar <path-to-created-jar> &
To detach the console screenPress: control + (A+D)