You have to edit the appropriate configuration files -- just setting the variables at the prompt affects your current session only.
I'm going to move this to our Linux/UNIX forum, where someone with a little more time than me will explain the details to you. In the meantime, you could try running "info bash" and reading the section on configuration files.
but when I try to run it as jboss (system user) using the command sudo -u jboss ./run.sh I still have the same problem. run.sh: Missing file: /lib/tools.jar run.sh: Unexpected results may occur. Make sure JAVA_HOME points to a JDK and not a JRE. =========================================================================
Unlike Windows, Linux has some very definite ideas of when to propagate environment variables and how. And, in the case of the "su" command, you can specify either that the su user be initialized as a clone of the current user environment, as a fresh login of the indicated user or as a completely clean environment. And maybe one or 2 other options.
Actually, it's really bad practice to depend on environmental setups when launching system init scripts, and you're seeing some of the reasons why.
A useful alternative is to setup the environment for a system task/daemon in /etc files. For example, create an /etc/default/jboss.conf file and define JAVA_HOME, JBOSS_HOME and whatever other environment variables you find useful in there. That allows you to make the init script itself portable. You just make the init script "source" the config file, leaving only invariant items in the init script.
JBoss's run.sh isn't done quite like the scripts in /etc/init.d, but it's close enough you can use that same general strategy.
Sometimes the only way things ever got fixed is because people became uncomfortable.