# how do I set JAVA_HOME? ... no seriously



## jigzat (Sep 24, 2011)

I had some issues starting Resin at boot and I as always I thought it was Resin's fault but it didn't. 

Resin is great. I found out that JAVA_HOME is not being set. Under sh I can't use *export JAVA_HOME=/...* I keep getting 
	
	



```
export: command not found
```
 If I set it under /etc/profile it just doesn't work neither under /etc/login.conf.

The only way to set it at least temporarily is going to bash and use the export command. Any ideas what is wrong? I need it to be set before resin.sh gets called. By the way I come from Linux but I guess you already suspected that.


----------



## ondra_knezour (Sep 24, 2011)

You can set it in resin.sh by command suported by shell in which is file executed.

In sh, export should work, but you are probably running csh/tcsh, where you want use setenv. Consult printenv() and env() manpages.

So in short you can:

 Set variable in profile of user, under which is command running (may not be you)
 Use `$ setenv JAVA_HOME=/somewhere && /path/to/resin.sh` if you are running csh (check man if there is equation sign or space, I can't remember now)
 Edit resin.sh and set variable there. Consult shebang line on top of file for shell which is running this file, probably sh.


----------



## jigzat (Sep 24, 2011)

Thank you for the answer, setenv actually worked but temporarily. As soon as I restart it goes back to "undefined variable" and putting it in resin.sh didn't have any effect. By the way I am running everything under root.


----------



## ramonovski (Sep 24, 2011)

Then add the variable to your shell configuration file.

By default for root: /root/.cshrc


----------



## wblock@ (Sep 24, 2011)

First, don't run as root.

Second, look at /usr/local/etc/rc.d/resin.sh.  It tries to set this environment variable for you.  Figuring out why that isn't working should help.


----------



## jigzat (Sep 25, 2011)

Thank you very much to all. You people answer fast. Anyway I have no idea what went wrong I had to reinstall FreeBSD  and after that I could successfully set JAVA_HOME on resin.sh. Any way it was a good learning experience I ended up using the resin.sh script that was created installing resin3 from ports and changed some things a bit. This is what I have:


```
#!/bin/sh
#
#
#

# PROVIDE: resin
# REQUIRE: LOGIN
# KEYWORD: shutdown

#
# Add the following line to /etc/rc.conf to enable resin3:
#
# resin_enable="YES"
#

. /etc/rc.subr

name=resin
rcvar=`set_rcvar`

command="/usr/local/resin/bin/resinctl"
command_args="start"
pidfile=/usr/local/resin/resin.pid

# set defaults

resin_enable=${resin_enable:-"NO"}
resin_user=${resin_user:-"root"}
resin_group=${resin_group:-"wheel"}

load_rc_config ${name}

JAVA_HOME="/usr/local/openjdk6";

export JAVA_HOME

run_rc_command "$1"
```

The part that says JAVA_HOME used to have this:


```
if test -n "${resin3_java_version}" ; then
    JAVA_HOME=$(JAVA_VERSION="${resin3_java_version}" JAVAVM_DRYRUN=1 /usr/$
    procname=$(JAVA_VERSION="${resin3_java_version}" JAVAVM_DRYRUN=1 /usr/l$
else
    JAVA_HOME=$(JAVAVM_DRYRUN=1 /usr/local/bin/java | grep JAVA_HOME | cut $
    procname=$(JAVAVM_DRYRUN=1 /usr/local/bin/java | grep JAVAVM_PROG | cut$
fi
```

the original code was generated when I installed resin3 from ports but It kept saying unexpected end of file: expected: ")" and if you see clearly there are 4 orphans "("  I don't know if it should be that way.

I'm going to try setting /root/.cshrc next time. I was certain that FreeBSD used sh but I was wrong.


----------



## fluca1978 (Sep 26, 2011)

jigzat said:
			
		

> I was certain that FreeBSD used sh but I was wrong.



Me too, maybe you changed the shell when you created the user?


----------



## ondra_knezour (Sep 26, 2011)

Shell for root user is csh in FreeBSD. Jigzat mentioned before he is running everything under root.


----------



## freethread (Sep 26, 2011)

Mine is a question but it is related to this context. The /etc/csh.cshrc, /etc/csh.login and /etc/csh.logout are _untoutchable_ in the same way as /etc/crontab?
If not, global environment variables can be set in the first file. That is true for all csh/tcsh users.


----------



## wblock@ (Sep 27, 2011)

Nothing in /etc is untouchable, although it's like everything else: there are good and bad ways, and sometimes it depends on the situation.

Here, modifying the root user's environment variables to run a port as root should be setting off all kinds of warning flags.  But before that, the resin.sh script not working is an indication that something is broken.  Maybe it's the port, but probably not.

(In message #6, the file isn't broken, it just has long lines indicated by the $.)


----------



## jigzat (Sep 27, 2011)

wblock@ said:
			
		

> Nothing in /etc is untouchable, although it's like everything else: there are good and bad ways, and sometimes it depends on the situation.
> 
> Here, modifying the root user's environment variables to run a port as root should be setting off all kinds of warning flags.  But before that, the resin.sh script not working is an indication that something is broken.  Maybe it's the port, but probably not.
> 
> (In message #6, the file isn't broken, it just has long lines indicated by the $.)



Good to know, I set the script to use root just in case it was somehow related to permissions. Anyway my goal is to use the www www user and group for that.


----------



## fluca1978 (Sep 27, 2011)

ondra_knezour said:
			
		

> Shell for root user is csh in FreeBSD. Jigzat mentioned before he is running everything under root.



Ops...sorry, didn't notice the use of root account. You are right, the shell for root is usually csh.


----------

