You can reduce the amount of memory java uses by using -Xmx
, but that needs to be called on the commandline that calls java. Luckily there are aliases.
This is not the same as changing the environment variables directly, so it might not solve your problem ultimately.
So, you write a wrapper script:
#!/bin/bash
alias java="java -Xmx120M"
alias javac="javac -J-Xmx120M"
shopt -s expand_aliases
source /path/to/the/original/script.sh
That way all calls to java someoption Someclass
will look like java -Xmx120M someoption Someclass
.
Of course this only works properly if there is no -Xmx
already present in the script that calls the problematic java code. And it only works if the called script doesn't call other scripts after it.
How does it work:
alias
replaces one command with another.
shopt -s expand_aliases
turns the aliasing feature on (but its resetted when a new script starts)
source ...somescript.sh
loads the other script inside this script as if it where one. This prevents the drawback of shopt mentioned above. But only one layer deep.