Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Andrzejek on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking $JAVA_HOME in Build Script

Status
Not open for further replies.

SwapSawe

Programmer
Apr 24, 2001
148
US
Hi All !!!

I have used tomcat, jsp, servlets to build my application under FreeBSD Unix Environment. Now I intend to produce a build script such that the user can get war file by running a simple "./BUILD.sh".

I am not considering using ANT because, the user might be aversive to using ANT. Or simply might not be aware of it.

My problem comes in when the user has not declared the $JAVA_HOME, now the build would fail in this case. Can you please suggest me a work around to this solution.

Many Thanks,

SwapSawe.

Cheer Up, The worst is yet to Come.
 
4 options :

1) Fail, alerting the user that they must set the env. var.
2) Prompt them to enter it during the script.
3) Execute a 'find / -type f |grep java' and hope you only find one version
4) Use Ant as its so easy to use

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Dear sedj !!!

Thanks for reply, my comments inline.

1) Fail, alerting the user that they must set the env. var.
There's the catch how do I go for it.
2) Prompt them to enter it during the script.
First I need to know how to check the JAVA_HOME.
3) Execute a 'find / -type f |grep java' and hope you only find one version
:), that is a very high expectation.
4) Use Ant as its so easy to use
As I said, if user doesnot want to use Ant, I am in trouble, I would have to give him customized script anyways.

Appreciated your efforts,

Looking forward to hear back.

Regards,

SwapSawe.

Cheer Up, The worst is yet to Come.
 
Hi

SwapSawe said:
First I need to know how to check the JAVA_HOME.
This goes to be more a scripting question for forum822 ( UNIX Scripting )

Theoretically :
Code:
if test -z "$JAVA_HOME"; then        [gray]# variable empty[/gray]
  echo "Error : JAVA_HOME not set"
  JAVA_HOME="`find / -name java | head -1`" [gray]# find java, keep first[/gray]
  JAVA_HOME=${JAVA_HOME%java}        [gray]# cut filename from path[/gray]
fi
if test -z "$JAVA_HOME"; then        [gray]# still empty[/gray]
  echo "Error : no java found"
  echo "Enter path to java :"
  read JAVA_HOME                     [gray]# interactive input[/gray]
fi
if test -z "$JAVA_HOME"; then        [gray]# still empty[/gray]
  echo "Error : no path entered"
  exit                               [gray]# nothing to do[/gray]
fi
Of course could be improved to ask the user to choose a java path if more then one found.

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top