Link to home
Start Free TrialLog in
Avatar of Tagom
Tagom

asked on

changing pointer for jre / jdk

Below is the file that I think sets the pointer for the jvm. Issue - I need some guidance in how to change this file without breaking apache tomcat
There are several jre's installed on my system and I would like to point it to one other than the default one in the system variables.
#!/bin/sh
# -----------------------------------------------------------------------------
#  Set CLASSPATH and Java options
#
#  $Id: setclasspath.sh 345508 2005-11-18 15:54:56Z yoavs $
# -----------------------------------------------------------------------------

# First clear out the user classpath
CLASSPATH=

# Make sure prerequisite environment variables are set
if [ -z "$JAVA_HOME" -a -z "$JRE_HOME" ]; then
  # Bugzilla 37284
  if $darwin && [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home" ]; then
    export JAVA_HOME="/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home"
  else
    echo "Neither the JAVA_HOME nor the JRE_HOME environment variable is defined"
    echo "At least one of these environment variable is needed to run this program"
    exit 1
  fi
fi
if [ -z "$JAVA_HOME" -a "$1" = "debug" ]; then
  echo "JAVA_HOME should point to a JDK in order to run in debug mode."
  exit 1
fi
if [ -z "$JRE_HOME" ]; then
  JRE_HOME="$JAVA_HOME"
fi

# If we're running under jdb, we need a full jdk.
if [ "$1" = "debug" -o "$1" = "javac" ] ; then
  if [ "$os400" = "true" ]; then
    if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/javac ]; then
      echo "The JAVA_HOME environment variable is not defined correctly"
      echo "This environment variable is needed to run this program"
      echo "NB: JAVA_HOME should point to a JDK not a JRE"
      exit 1
    fi
  else
    if [ ! -x "$JAVA_HOME"/bin/java -o ! -x "$JAVA_HOME"/bin/jdb -o ! -x "$JAVA_HOME"/bin/javac ]; then
      echo "The JAVA_HOME environment variable is not defined correctly"
      echo "This environment variable is needed to run this program"
      echo "NB: JAVA_HOME should point to a JDK not a JRE"
      exit 1
    fi
  fi
fi
if [ -z "$BASEDIR" ]; then
  echo "The BASEDIR environment variable is not defined"
  echo "This environment variable is needed to run this program"
  exit 1
fi
if [ ! -x "$BASEDIR"/bin/setclasspath.sh ]; then
  if $os400; then
    # -x will Only work on the os400 if the files are:
    # 1. owned by the user
    # 2. owned by the PRIMARY group of the user
    # this will not work if the user belongs in secondary groups
    eval
  else
    echo "The BASEDIR environment variable is not defined correctly"
    echo "This environment variable is needed to run this program"
    exit 1
  fi
fi

# Set the default -Djava.endorsed.dirs argument
JAVA_ENDORSED_DIRS="$BASEDIR"/common/endorsed

# Set standard CLASSPATH
if [ "$1" = "debug" -o "$1" = "javac" ] ; then
  CLASSPATH="$JAVA_HOME"/lib/tools.jar
fi

# OSX hack to CLASSPATH
JIKESPATH=
if [ `uname -s` = "Darwin" ]; then
  OSXHACK="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes"
  if [ -d "$OSXHACK" ]; then
    for i in "$OSXHACK"/*.jar; do
      JIKESPATH="$JIKESPATH":"$i"
    done
  fi
fi

# Set standard commands for invoking Java.
  _RUNJAVA="$JRE_HOME"/bin/java
if [ "$os400" != "true" ]; then
  _RUNJDB="$JAVA_HOME"/bin/jdb
fi
_RUNJAVAC="$JAVA_HOME"/bin/javac

Open in new window

Avatar of for_yan
for_yan
Flag of United States of America image

did you try to change JAVA_HOME environment variable ?
Avatar of Tagom
Tagom

ASKER

My boss does not want to change the system environmental variables....I actually had to have one of our tech supports download the newest java 6 to get the app working on a production machine. Our primary application is run under glassfish - the secondary is run under apache. I need to point the apache application to the jre/jdk installed with glasssfish - not nec. the jre listed in the environmental variables.

just copy this scriopt and go into the code and replace JAVA_HOME with actual values where your desired JDK is sitting and it should work the same without
modifying environemnt variables
Avatar of Tagom

ASKER

To make sure that I understand you correctly:
I have replaced the JAVA_HOME instances with d:/MyJavaDirectory (assuming that is where my jre would be). I then restart the apache server and all web apps installed should still work?
Here is what i did to the file
#!/bin/sh
# -----------------------------------------------------------------------------
#  Set CLASSPATH and Java options
#
#  $Id: setclasspath.sh 345508 2005-11-18 15:54:56Z yoavs $
# -----------------------------------------------------------------------------

# First clear out the user classpath
CLASSPATH=

# Make sure prerequisite environment variables are set
if [ -z "$d:/MyJavaDirectory" -a -z "$JRE_HOME" ]; then
  # Bugzilla 37284
  if $darwin && [ -d "/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home" ]; then
    export d:/MyJavaDirectory="/System/Library/Frameworks/JavaVM.framework/Versions/1.5/Home"
  else
    echo "Neither the d:/MyJavaDirectory nor the JRE_HOME environment variable is defined"
    echo "At least one of these environment variable is needed to run this program"
    exit 1
  fi
fi
if [ -z "$d:/MyJavaDirectory" -a "$1" = "debug" ]; then
  echo "d:/MyJavaDirectory should point to a JDK in order to run in debug mode."
  exit 1
fi
if [ -z "$JRE_HOME" ]; then
  JRE_HOME="$d:/MyJavaDirectory"
fi

# If we're running under jdb, we need a full jdk.
if [ "$1" = "debug" -o "$1" = "javac" ] ; then
  if [ "$os400" = "true" ]; then
    if [ ! -x "$d:/MyJavaDirectory"/bin/java -o ! -x "$d:/MyJavaDirectory"/bin/javac ]; then
      echo "The d:/MyJavaDirectory environment variable is not defined correctly"
      echo "This environment variable is needed to run this program"
      echo "NB: d:/MyJavaDirectory should point to a JDK not a JRE"
      exit 1
    fi
  else
    if [ ! -x "$d:/MyJavaDirectory"/bin/java -o ! -x "$d:/MyJavaDirectory"/bin/jdb -o ! -x "$d:/MyJavaDirectory"/bin/javac ]; then
      echo "The d:/MyJavaDirectory environment variable is not defined correctly"
      echo "This environment variable is needed to run this program"
      echo "NB: d:/MyJavaDirectory should point to a JDK not a JRE"
      exit 1
    fi
  fi
fi
if [ -z "$BASEDIR" ]; then
  echo "The BASEDIR environment variable is not defined"
  echo "This environment variable is needed to run this program"
  exit 1
fi
if [ ! -x "$BASEDIR"/bin/setclasspath.sh ]; then
  if $os400; then
    # -x will Only work on the os400 if the files are:
    # 1. owned by the user
    # 2. owned by the PRIMARY group of the user
    # this will not work if the user belongs in secondary groups
    eval
  else
    echo "The BASEDIR environment variable is not defined correctly"
    echo "This environment variable is needed to run this program"
    exit 1
  fi
fi

# Set the default -Djava.endorsed.dirs argument
JAVA_ENDORSED_DIRS="$BASEDIR"/common/endorsed

# Set standard CLASSPATH
if [ "$1" = "debug" -o "$1" = "javac" ] ; then
  CLASSPATH="$d:/MyJavaDirectory"/lib/tools.jar
fi

# OSX hack to CLASSPATH
JIKESPATH=
if [ `uname -s` = "Darwin" ]; then
  OSXHACK="/System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK/Classes"
  if [ -d "$OSXHACK" ]; then
    for i in "$OSXHACK"/*.jar; do
      JIKESPATH="$JIKESPATH":"$i"
    done
  fi
fi

# Set standard commands for invoking Java.
  _RUNJAVA="$JRE_HOME"/bin/java
if [ "$os400" != "true" ]; then
  _RUNJDB="$d:/MyJavaDirectory"/bin/jdb
fi
_RUNJAVAC="$d:/MyJavaDirectory"/bin/javac

Open in new window

I don't understand-
Are you ruunning it on winodws - why d:/MyJavaDirectory
I thought you are in Unix environemnt?


>My boss does not want to change the system environmental variables

You don't need to change system enevironement
Just change JAVA_HOME in the same terminal where you are going to run this script
before you run the script - it will not affect anything else
ASKER CERTIFIED SOLUTION
Avatar of for_yan
for_yan
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tagom

ASKER

The applications are installed on windows systems. We use localhost to access the applications, changing the port numbers.
This script is not run in a terminal window, it is part of the tomcat 6 setup.
I might very well be relaying what I need incorrectly - This is the working of the request:

Research: how to configure JasperServer to use a different jre/jdk find out if its possible and how for both v3 and v4 of jasper server.
Every server we deploy (windows server) has glassfish on it, and every glassfish as the full jdk and jre bundled inside - d:\java\sdk\jdk and d:\java\sdk\jdk\jre but neither are registered on the path or java_home variable.
if there is a configuration file inside jasperServer that allows us to specify the path to the jre, we need to know what else that file might contain - i.e. is it machine specific?  if it has machine name or ip in it, than we might be able to use localhost globally, but if it has settings specific to the machine, it might not work to copy from one server to another.
Avatar of Tagom

ASKER

JasperServer it installed in a separate tomcat installation.
in here
http://www.mulesoft.com/tomcat-start

raed this:


----
Manual Start-Up For Windows Distributions

There are two ways of manually starting Tomcat on a Windows machine; one is to execute "catalina.bat start" or "startup.bat" from the command line.  

The other way, if you've installed Tomcat as a service, is to use the manager tool Tomcat6w.exe, a small GUI program that resides in the task bar after it has been run.  Double-clicking its icon will open a tabbed dialog window, which includes a start-up button, and can also be used to configure a few start up options.  

If you don't know if you've installed Tomcat as a Windows Service, don't worry - this is covered in the Automatic Start-Up section.  However, as a quick rule of thumb, if you installed Tomcat using the Windows EXE installer, Tomcat was also installed as a service automatically.

----
If you are running Tomact as service - try to double-click the icon and check if they
have option ti change JAVA_HOME there

If not, then you can rather start Tomact not as service - for that
open Dos command line window

set JAVA_HOME=d:\MyJavaDierctory

then go to Tom,act home and then execute
"catalina.bat start" or "startup.bat" from the command line

Again your JAVA_HOME will affect only commands in the DOS window where you issued it

Avatar of Tagom

ASKER

okay, so I am still fighting with this.
Here is what I am finding and what I have tried:
1. tomcat is being installed part of jasperServer
2. it is therefore NOT installed as a service automatically
3. when our setup installs the service it installs under a different name then tomcat5
5. tomcatw will not execute because it looks to tomcat5
6. boss does not want to change name of service back to tomcat5
7.Her preferred solution: that we can create a file which will point to a different java_home as the one we install with glassFish is always the same - never updated/changed type of situation

WHAT if have tried
tried adding the
set JAVA_HOME = D:\java\sdk\jdk
to the catalina.bat file (which I understand to be the startup file for tomcat5)
This makes not difference in the startup

I CAN NOT touch the system variables and I am not understanding if running the set java_home from command line at the time of install will have to be done every time the server is starting or if it will change any other applications using java_home

Avatar of Tagom

ASKER

also added
set JRE_HOME to the bat file
when trying to start the server this is the error i get
[2012-01-18 14:30:47] [info] Starting service...
[2012-01-18 14:30:47] [173  javajni.c] The specified module could not be found.
[2012-01-18 14:30:47] [924  prunsrv.c] Failed creating java
[2012-01-18 14:30:47] [1179 prunsrv.c] ServiceStart returned 1
[2012-01-18 14:30:47] [info] Run service finished.

I'm not sure I understand.

So you are not starting Tomcat manually?
It is some other process, which starts it for you correct?

Avatar of Tagom

ASKER

it is trying to start automatically using the service installed as JasperServer - this is a windows environment
The directory which the service points to is
D:\java\jasperserver-ce-3.7.0\apache-tomcat\bin\tomcat5.exe //RS//JasperServer

when i try and start the service via "services" the following error pops up
refer to service-specific error code 0

I appreciate you staying with me on this!
If so, then we don't know how tomcat is actually being started, becuase we cannot say what is going on
within tomcat.exe
Avatar of Tagom

ASKER

I was afraid you were going to say that!
So you do not know which file in tomcat5 I would manually set the java_home variable
all the research I find points to the catalina.bat file but as i said it is not working for me
Because research is about general case - if you would start tomcat manually yourself.

Maybe you could try to find something in documentation of JasperReports.
As they are preparing evrything about tomcat for you - maybe they specify somewhere how to change JVM
which drives Tomcat.

Is there any JVM setting for JasperReports ?
They will probably use for Tomcat the same JVM which runs JasperReports ?
Avatar of Tagom

ASKER

i have not looked checking now.
This is what is in the jaspserctl file

rem ============== TOMCAT =============

:tomcat

set JAVA_HOME=D:\java\jasperserver-ce-3.7.0\java
set JRE_HOME=D:\java\jasperserver-ce-3.7.0\java
set CATALINA_HOME=D:\java\jasperserver-ce-3.7.0\apache-tomcat

if ""%2"" == ""stop"" goto tomcat_stop
if ""%2"" == ""restart"" goto tomcat_restart
goto tomcat_start

:tomcat_start

echo Starting Tomcat Server...
call "%CATALINA_HOME%\bin\startup.bat"
if ""%2"" == ""start"" goto end
goto end

:tomcat_stop
echo Tomcat server shutting down...
call "%CATALINA_HOME%\bin\shutdown.bat"
if ""%2"" == ""stop"" goto end
ping localhost -n 4 >NUL
if ""%2"" == ""restart"" goto tomcat_start

:tomcat_restart
goto tomcat_stop
goto end

rem ============== APACHE ===========

:apache

if ""%2"" == ""stop"" goto apache_start
if ""%2"" == ""restart"" goto apache_restart
goto apache_start

:apache_start

echo Starting Apache Server...
start "BitRock Apache Server - Closing this window will shutdown the server" /MIN "@@BITROCK_APACHE_ROOTDIR@@/bin/apache.exe"
goto end

:apache_stop
echo Apache server shutting down...
call taskkill.exe /FI "WINDOWTITLE eq BitRock Ap*"
if ""%2"" == ""stop"" goto end
ping localhost -n 4>NUL
if ""%2"" == ""restart"" goto apache_restart

:apache_restart
goto apache_stop
goto end

:end

it seems to me that it still points back to the catalina.bat file or the startup.bat file!
I think it point to startup.bat in catalina home directory

Try to modify JAVA_HOME within that one

SO you want TOMCAT to run form different java than the rest of JasperReports?

Mayeb it will cause problems? They do it with the same java and maybe it is important for them?

Avatar of Tagom

ASKER

No I do not thinks so - what I am seeing is this
IF I install jre to the default settings from sun.com the server starts perfectly - however the install does not change the
 jaspserctl
  This is set up very strangely to me.
I don't udnerstand - if you instakll new JRE on yor machine - of course nothing will change - as theyset up JAVA_HOME inside their script pointing to the Java
they installed with theor Jasperreports. No matter what other java you install nothing would change - untill you
modify that script in jaspercntl
and I don't think it is a good idea to change it.
They had the purpose in having their own java which they install to run Jaspeersreposrt
Avatar of Tagom

ASKER

for_yan
So not that I have spend a few days reading! I think I understand more directly what you are trying to communicate with me.
This is now what I know and understand:
I CAN set the Java_Home via command line using tomcat5w - even with the tomcat5 service named JasperServer!
I also believe if I understand correctly that I can implement the tomcat5 server via command line and change the java_home then -

Issues - If I understand this correctly I need to permanently change the specific variables for tomcat5 as a service - so that it starts correctly everytime the machine is rebooted - (automatically not manually)
with this said I believe I need to focus on the tomcat5w tool.
I have tried this command
D:\java\jasperserver-ce-3.7.0\apache-tomcat\bin>tomcat5w //US//JasperServer --Ja
vaHome="D:\java\sdk\jdk"

Open in new window


however I get this error
unknown command line option ' //US//JasperServer --Ja
vaHome="D:\java\sdk\jdk"
See the manual for command line usage
The only manual I find is here:
http://tomcat.apache.org/tomcat-5.5-doc/windows-service-howto.html

So I am assuming that I have my syntax incorrectly - how would I need to change this?
Avatar of Tagom

ASKER

UPDATE This will pull up the window to alter the configuration - however I do not want the window I want to just be able to run the bat file and it auto set the info

D:\java\jasperserver-ce-3.7.0\apache-tomcat\bin>tomcat5w //ES//JasperServer --Di
splayName
Avatar of Tagom

ASKER

D:\java\jasperserver-ce-3.7.0\apache-tomcat\bin>tomcat5w //US//JasperServer --Ja
vaHome="D:\java\sdk\jdk\jre\bin\client"
If tomcat5w follows the same as tomcat5 - I don't think you need necessarrily
to do it in command line.

It shows that deafulat for JavaHome is contens of JAVA_HOME environement variable
--JavaHome JAVA_HOME

then you can do it independntly:

set JAVA_HOME=D:\java\sdk\jdk

and then start service

Maybe better not to update but to delete and then to specify JAVA_HOME and  to install the service again

 
Avatar of Tagom

ASKER

Okay, so I have deleted the service -
Here is the bat file we use to install the service when application is deployed -
I would like to add the set option to this file - is it doable -
BTW - I have LEARNED SO MUCH with you on this. thank you immensely.
@echo off
cScript.exe //B //Nologo "%~3\Shared\WriteMUSLog.vbs" "%~3" JasperServer.bat "jsServiceSetup.bat [Start]"

:installTomcat
cScript.exe //B //Nologo "%~3\Shared\WriteMUSLog.vbs" "%~3" JasperServer.bat "Installing JasperServer service handle."
echo Installing JasperServer service handle.
cd "%~3\..\Java\jasperserver-ce-3.7.0\apache-tomcat\bin"
service install JasperServer \--JVM=								>> "%~3\Logs\Installation\JasperServer.log" 2

Open in new window

Yes, you can set comman line arguments on your .bat file, see here:
and you can check them in the code using "%1", "%2", see below link for the example:

http://www.robvanderwoude.com/parameters.php



So if you add "%1" in the end
then running it  as

my_batch_file d:\java\sdk\jdk

should transfer your command line paramtere value to the appropriate position in the file

@echo off
cScript.exe //B //Nologo "%~3\Shared\WriteMUSLog.vbs" "%~3" JasperServer.bat "jsServiceSetup.bat [Start]"

:installTomcat
cScript.exe //B //Nologo "%~3\Shared\WriteMUSLog.vbs" "%~3" JasperServer.bat "Installing JasperServer service handle."
echo Installing JasperServer service handle.
cd "%~3\..\Java\jasperserver-ce-3.7.0\apache-tomcat\bin"
service install JasperServer \--JVM="%1"								>> "%~3\Logs\Installation\JasperServer.log" 2

Open in new window

or actually you don't need even quotes:

@echo off
cScript.exe //B //Nologo "%~3\Shared\WriteMUSLog.vbs" "%~3" JasperServer.bat "jsServiceSetup.bat [Start]"

:installTomcat
cScript.exe //B //Nologo "%~3\Shared\WriteMUSLog.vbs" "%~3" JasperServer.bat "Installing JasperServer service handle."
echo Installing JasperServer service handle.
cd "%~3\..\Java\jasperserver-ce-3.7.0\apache-tomcat\bin"
service install JasperServer \--JVM=%1							>> "%~3\Logs\Installation\JasperServer.log" 2

Open in new window