Search code examples
javalinuxjavaagents

javaagent option does not expand the tilde but why not


This invocation works.

java -ea -cp ~/Documents/workspace/export/testProject1/"*" -javaagent:/home/jack/Documents/workspace/export/testProject1/SizeOf.jar testProject1.Tester

This invocation fails.

java -ea -cp ~/Documents/workspace/export/testProject1/"*" -javaagent:~/Documents/workspace/export/testProject1/SizeOf.jar testProject1.Tester

The failure looks like this.

    Error opening zip file or JAR manifest missing : 
    ~/Documents/workspace/export/testProject1/SizeOf.jar
    Error occurred during initialization of VM
    agent library failed to init: instrument

Why does the the -javaagent option fail to expand the tilde (~). This was on Linux.


Solution

  • The tilde is expanded by the shell, not the program being run, and it wasn't at the beginning of the token. Use "$HOME" instead.