Search code examples
javapowershelljar

PowerShell get or stop a particular Java process


I am using PowerShell script to start multiple Java application.

$app = Start-Process -FilePath java -ArgumentList "-jar $path_to_jar" -PassThru

it's working as expected.

But I also have to search a particular Java process and stope/close it.
I cant use process id ($app.ID) as stop script will be a different script.

Can I have some custom name/identifier to these Java process to get a particular process ? like if I can fetch a java process by JAR name etc.

Not sure but in Linux environment I have seen use of -DAPP_INSTANCE_NAME flag , that might be a custom flag to identify a process.

Any help is apricated.


Solution

  • Finally I am using JPS , it's command

    & jps -v 
    

    returning all the details like jar name etc. and that result I am using for filtering out the process id.