If you want to see more of the command line, with many ps implementations including that from procps¹ on Linux, you can just add the -w option (or w with the BSD-style API you're using), twice to get the full command line²:
ps auxww # BSD-style ps -Afww # standard style
procps' ps also has a -C option to report processes running a given command (using heuristics), so you can do:
ps -fwwC java
To list the full command lines of java processes.
On GNU/Linux, to reliably find processes that have file.jar as one of the arguments passed to the command it (or its ancestor) executed, you can do:
grep -lFzx file.jar /proc/*/cmdline
(lists the files that have at least one zero-delimited record that matches file.jar as a Fixed string and exactly (not as a substring)).
Or to limit it to processes running /usr/bin/java:
find /proc -maxdepth 2 \ -name cmdline \ -execdir test exe -ef /usr/bin/java ';' \ -exec grep -lFzx file.jar {} +
Or shorter and more efficient with the zsh shell:
print -rC1 /proc/<2->(e[$' [[ $REPLY/exe -ef /usr/bin/java && \0$(<$REPLY/cmdline) = *\0file.jar\0* ]] ']:t)
(replace print -rC1 with kill to kill those processes).
With that approach, you can make the selection stricter by selecting only those processes that have file.jar as the next argument after a -jar one by changing the pattern to *\0-jar\0file.jar\0*.
Using pkill as suggested by @kos is probably good enough though and can be made stricter with:
pkill -f '^java (.* )?-jar file\.jar( |$)'
It's not as reliable as:
- it doesn't check what executable is being run, just the arguments that are passed to it.
- it could run into the 128KiB limit (and for instance match on a command line that has
-jar file.jarringly.unlikely.jar at the end of an extremely long java command line) - as arguments are joined with spaces we lose the information of where each starts and ends, so it could match on a process that was started with
'java and lambada' -f 'jam -jar file.jar' for instance. - it will fail if there are byte sequences in the command line that can't be decoded into characters in the locale's encoding.
All of which are extremely unlikely.
¹ The most commonly used one on non-embedded operating systems using Linux as their kernel.
² still limited to 128KiB with the ps from procps, and beware that older versions of Linux only exposed the first 4KiB of the command line (argument list) in /proc/<pid>/cmdline where ps gets the information from.