How to set JAVA_HOME programatically

Hi Friends,
Is there anyway to set JAVA_HOME environment property using a batch script.Actually,I am trying to check if the user system has java installed or not. If not,I make him run the JRE installer but the problem is when I try to start Tomcat, it expects JAVA_HOME to be set. So, I want to set JAVA_HOME programatically, is there anyway to do so???
This is the script i am using to check if java is already installed or not:
@echo off
::This batch file only tested under Windows 2000
::It will detect the short path of the current version
::of the Java runtime executable
::First test to see if we are on NT or similar OS by seeing
::if the ampersand is interpreted as a command separator
reg1.txt echo 1234&remtype reg1.txt | find "rem"
if not errorlevel 1 goto WIN9X
::Find the current (most recent) Java version
start /w regedit /e reg1.txt "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment"
type reg1.txt | find "CurrentVersion" > reg2.txt
if errorlevel 1 goto ERROR
for /f "tokens=2 delims==" %%x in (reg2.txt) do set JavaTemp=%%~x
if errorlevel 1 goto ERROR
echo Java Version = %JavaTemp%
del reg1.txt
del reg2.txt
::Get the home directory of the most recent Java
start /w regedit /e reg1.txt "HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Runtime Environment\%JavaTemp%"
type reg1.txt | find "JavaHome" > reg2.txt
if errorlevel 1 goto ERROR
for /f "tokens=2 delims==" %%x in (reg2.txt) do set JavaTemp=%%~x
if errorlevel 1 goto ERROR
echo Java home path (per registry) = %JavaTemp%
del reg1.txt
del reg2.txt
::Convert double backslashes to single backslashes
set JavaHome=
:WHILE
  if "%JavaTemp%"=="" goto WEND
  if not "%JavaHome%"=="" set JavaHome=%JavaHome%\
  for /f "delims=\" %%x in ("%JavaTemp%") do set JavaHome=%JavaHome%%%x
  for /f "tokens=1,* delims=\" %%x in ("%JavaTemp%") do set JavaTemp=%%y
  goto WHILE
:WEND
set JavaTemp=
echo Java home path (long, with spaces) = %JavaHome%
::Convert long path (with spaces) into a short path
for %%x in ("%JavaHome%") do set JavaHome=%%~dpsx
echo Java home path (short path, no spaces) = %JavaHome%
::Test the java path to see if there really is a java.exe
if not exist %JavaHome%\bin\java.exe goto ERROR
::Make changes to the PATH
echo Insert code here that needs to know the short path to Java.
set path=%JavaHome%\bin;%path%
goto DONE
:WIN9X
echo Insert code here for Windows 9x
goto DONE
:ERROR
echo Insert code here for conditions where Java.exe can't be found
goto DONE
:DONEThanks

You are asking questions about Windows batch scripting in a Java forum?
When you get right down to it, the question is "How do I set an environment variable in a batch script", isn't it? Free your mind from useless distractions: the batch script and the operating system don't care at all what you're going to use that environment variable for.
Oh yeah, I almost forgot: you use the SET command to set an environment variable.

Similar Messages

  • How to set JAVA_HOME in solaris9

    hello all,
    Do some one give me some url's or information how to set JAVA_HOME, CLASSPATH and related environmental setting for SOLARIS 9 operating system.
    thanQ,
    Han.

    solaris is the unix-like OS
    so try to find the same info about linux, freebsd or other unix os
    in general try export or set command

  • How to set JAVA_HOME

    Hi,
    can any body tell how to set the JAVA_HOME variable for the
    windows 95/98 operating system. Iam using the "jakarta-tomcat-3.2.1"
    server for running the jsp files. I could do it in window NT os by setting up in the environment option of the mycomputer properties. I
    couldn't know how to set it in the window 95/98 os
    phani

    To set the JAVA_HOME variable in Windows 95/98 you have to edit the file autoexec.bat located on your hard drive and add a line similar to this one.
    SET JAVA_HOME=C:\J2SDK1.4.1
    Where c:\j2sdk1.4.1 is the directory where java is installed.
    Hope this helps.

  • How to set JAVA_HOME and ANT_HOME in OSX 10.9.5

    Hi
    recently we moved to 10.9.5 and i dnt see .profile file at home. can you please let me know how to set up JAVA_HOME and ANT_HOME
    when ever i set those at termanil with export commands . those are getting vanished after closing the terminal. pls let me know how to set up PATHs at 10.9.5.
    since i dnt see the profile file.
    Thanks
    Pasunoori

    Modify .bash_profile.

  • How to set JAVA_HOME in REDHAT 9.0 Linux?

    I was trying to set JAVA_HOME in profile file, but unable to decide where to put the java_home path. Can anyone guide me?
    J2sdk and JRE are in /USR/JAVA

    It is sufficient to set PATH.
    In Unix (including Linux) most file systems are case-sensitive regarding the file and directory names. So /USR/JAVA is different from /usr/java.

  • Linux: how to set JAVA_HOME in startup script?

    My Linux box cannot find JDK classpath.
    How do I set CLASSPATH and JAVA_HOME in a script file that is loaded at startup?
    Thanks!

    What are you trying to do? If you are executing a script that runs a java process in cron, or something, then simpl place these lines in that script before the call to java.
    All environment variables are set when the shell starts. Every process is run under a shell, and that shell is what has the environment variables. Which environment variables it has, depends on which shell is started, and how that shell is started.
    Cron, and some users, have a very limited shell environment. Even these shell environments are configurable though. How this is done, however, is not a topic for this forum.

  • Setting ServletReloadCheckSecs programatically

    Hello,
              In config.xml, under Domain->Application->WebAppComponent, there is an
              attribute called ServletReloadCheckSecs that is used by weblogic to
              decide whether to check a war file for update and how frequent should
              the check be. The default is 1 sec.
              The only way to change this number, short of editing config.xml after
              deployment, is to use the console. Does anyone know how to set this
              programatically? Like as an argument to weblogic.Deployer or as an
              attribute in web.xml?
              Thanks,
              Chishun Kwong
              

              "Chishun Kwong" <[email protected]> wrote in message
              news:[email protected]..
              > Hello,
              >
              > In config.xml, under Domain->Application->WebAppComponent, there is an
              > attribute called ServletReloadCheckSecs that is used by weblogic to
              > decide whether to check a war file for update and how frequent should
              > the check be. The default is 1 sec.
              >
              > The only way to change this number, short of editing config.xml after
              > deployment, is to use the console. Does anyone know how to set this
              > programatically? Like as an argument to weblogic.Deployer or as an
              > attribute in web.xml?
              >
              > Thanks,
              > Chishun Kwong
              In web.xml adding the following should work for you
              <context-param>
              <param-name>weblogic.servlet.reloadCheckSecs</param-name>
              <param-value>-1</param-value>
              </context-param>
              If you are using weblogic 7.x or 8.1 you can alternatively set this
              parameter in weblogic.xml
              http://e-docs.bea.com/wls/docs81/webapp/weblogic_xml.html#1038823
              <container-descriptor>
              <servlet-reload-check-secs>-1 </servlet-reload-check-secs>
              </container-descriptor>
              hope that helps
              Nagesh
              

  • How to set the value of an LOV in CO prgramatically and get the Pkey value?

    Hi,
    I need to set a value to a LOV, say ItemLOV in a page through CO and get the Primaykey that LOV will return. How can I achieve this?
    Req:
    1. Set the Item_Name, say 'DELL_1618' so that the page displays this in the LOV.
    2. Fetch the PK value returned by LOV in the backend into a VO attribute say Item_ID, '100009881'.
    Thanks,
    Santosh.

    Hi Santosh,
    Sorry, I replied for General LOV Scenario, but want to set it programatically right,
    You need to execute your LOV query in Controller for Item 'DELL_1618' using prepared statement, get the value for both dispaly value and Id and set it to LOV and FormVlaue Item in PR of controller.
    Regards,
    Reetesh Sharma

  • How to set classpath in WinXP Home edition

    Hello everyone,
    Recently I have try to run the HelloWorld java code, but it come up with a error. (Exception in thread �main� java.lang.NoClassDefFoundError: HelloWorld)
    Java programming Code:
    public class HelloWorld {
    public static void main (String args[]) {
    System.out.println("Hello World!");
    I also try to compile another simple program, and it come up with the simpler error, (Exception in thread �main� java.lang.NoClassDefFoundError: Add16And23)
    Java programming Code:
    public class Add16And23
         public static void main (String[] args)
              int sum;
              sum=16+23;
              System.out.println("The sum of 16 and 23 is " + sum);
    HOW CAN I FIX THIS, I read other threads before, it say some about class path.
    Do anyone know how to set it, in winXP?
    Do anyone know the whole path that I should put in, in winXP?
    What should I type in the (User variables for windows) and (System variables).
    I have :
    * (j2eesdk-1_4-dr-windows-eval) downloaded and installed;
    *&#61623;WinXP Home edition Version 2002 Service Pack 1
    * My current Java path are (C:\Sun\AppServer\jdk\bin) in the (User variables for windows).
    Please help!!!
    Thank you all!!!

    I'm also windows xp.
    fllowing example:
    java_home=c:\j2sdk1.4.2_03\bin
    classpath=c:\j2sdk1.4.2_03\dt.jar;c:\j2sdk1.4.2_03\tool
    .jarThis won't fix a thing.
    When you run, do it like this:
    java -classpath . HelloWorldNote the "dot" after -classpath. That tells the class loader to look in the current directory for the .class files it needs.
    Read about how to run the javac.exe and java.exe tools in your javadocs. You'll have to learn about CLASSPATH. - MOD

  • JAAS in Java StoredProcedures: How to set up LoginModule

    Hi,
    has anyone tried to use JAAS in a Java StoredProcedure on Oracle9i?
    I couldn't find out how to set up the JVM to find the login configuration. Here the error I get, whenn I run the StoredProcedure:
    ORA-29532: Java call terminated by uncaught Java exception: java.lang.SecurityException: Unable to locate a login configuration
    Here is what I did so far:
    1. copy jaas.jar into the $JAVA_HOME/lib/ext directory
    2. add to $JAVA_HOME/lib/security/java.security
    login.config.url.1=file:C:/my_jaas.config
    3. provide configuration file my_jaas.config
    Test {
    auth.MyLoginModule required debug=true;
    4. loadjava for jaas.jar (TEST schema)
    5. setup of the database security:
    dbms_java.grant_policy_permission( 'JAVA_ADMIN', 'TEST', 'javax.security.auth.AuthPermission', '*' );
    dbms_java.grant_permission( 'TEST', 'TEST:javax.security.auth.AuthPermission', 'createLoginContext', null );
    dbms_java.grant_permission( 'TEST', 'TEST:javax.security.auth.AuthPermission', 'getLoginConfiguration', null );
    dbms_java.grant_permission( 'TEST', 'SYS:java.security.SecurityPermission', '*', null );
    6. loadjava for the StoredProcedure (TEST schema)
    LoginContext lc = new LoginContext( "Test", new TestCallbackHandler() );
    lc.login();
    How can I tell the database where to look for the login configuration. Am I missing something here?
    Thanks for any help
    Regards,
    Christian

    Hi,
    has anyone tried to use JAAS in a Java StoredProcedure on Oracle9i?
    I couldn't find out how to set up the JVM to find the login configuration. Here the error I get, whenn I run the StoredProcedure:
    ORA-29532: Java call terminated by uncaught Java exception: java.lang.SecurityException: Unable to locate a login configuration
    Here is what I did so far:
    1. copy jaas.jar into the $JAVA_HOME/lib/ext directory
    2. add to $JAVA_HOME/lib/security/java.security
    login.config.url.1=file:C:/my_jaas.config
    3. provide configuration file my_jaas.config
    Test {
    auth.MyLoginModule required debug=true;
    4. loadjava for jaas.jar (TEST schema)
    5. setup of the database security:
    dbms_java.grant_policy_permission( 'JAVA_ADMIN', 'TEST', 'javax.security.auth.AuthPermission', '*' );
    dbms_java.grant_permission( 'TEST', 'TEST:javax.security.auth.AuthPermission', 'createLoginContext', null );
    dbms_java.grant_permission( 'TEST', 'TEST:javax.security.auth.AuthPermission', 'getLoginConfiguration', null );
    dbms_java.grant_permission( 'TEST', 'SYS:java.security.SecurityPermission', '*', null );
    6. loadjava for the StoredProcedure (TEST schema)
    LoginContext lc = new LoginContext( "Test", new TestCallbackHandler() );
    lc.login();
    How can I tell the database where to look for the login configuration. Am I missing something here?
    Thanks for any help
    Regards,
    Christian Hi, this is not supported yet - although some guys, on the forum, successfully implements JSSE but i am not allowed to disclose how they did it.
    we hope to provide formal support for JAAS, JSSE and JCE in upcoming major database release
    Kuassi

  • How to set server log file severity

    Will some one suggest how to set the severity for messages logged by server to server log file. The admin console consists of setting "Stdout Severity Threshold" which is applicable only to standard out. I need to restrict info messages to be logged in server log file.

    Which release of WebLogic Server are you using? In WebLogic 9.0 there is an attribute on the LogMBean called LogFileSeverity which could be configured to "Warning" so it will not allow Debug and Info level messages to be written to the server log file. In the 8.1 release you would need to do this programatically using a startup class, by getting a reference to the server Logger by invoking weblogic/logging/LoggingHelper.getServerLogger() and setting the appropriate weblogic/logging/WLLevel on the weblogic/logging/FilestreamHandler that writes to the server log file.
    Hope this helps
    Sandeep

  • Simple question: How to set a different image to each side of a 3D cube?

    Hi all,
    I'm very new in the use of Java 3D and I would like to know how to set, in a 3D cube, for each side a different image.
    Currently I've the code to set an image as texture of the cube, but it applies the same image to all the sides. However, I would like to use different images for each side.
    This is my code: http://pastebin.com/sexBx57K
    Any clue?
    Thanks!

    I think I worked it out.
    I just have to set the JAXP parser
    Q. How do I use a different JAXP compatible implementation?
    The JAXP 1.1 API allows applications to plug in different JAXP compatible implementations of parsers or XSLT processors. For example, when an application wants to create a new JAXP DocumentBuilderFactory instance, it calls the staic method DocumentBuilderFactory.newInstance(). This causes a search for the name of a concrete subclass of DocumentBuilderFactory using the following order:
    1. The value of a system property like javax.xml.parsers.DocumentBuilderFactory if it exists and is accessible.
    2. The contents of the file $JAVA_HOME/jre/lib/jaxp.properties if it exists.
    3. The Jar Service Provider discovery mechanism specified in the Jar File Specification. A jar file can have a resource (i.e. an embedded file) such as META-INF/services/javax.xml.parsers.DocumentBuilderFactory containing the name of the concrete class to instantiate.
    4. The fallback platform default implementation.

  • Setting JAVA_HOME environment variable?

    Sorry for such a trivial question, but in Windows 2000 Server with Microsoft Visual J++ 6 and the JRK 1.1.8, can somebody tell me what the environment variables should be so that I can use this jdk? If not can you tell me what your environment variable JAVA_HOME points to?
    And one last question if it's not too much to ask. Can you tell me the NNTP server address for SUN so that I can go to the newsgroups in my News reader rather than over the web?
    Thanks.
    George Hester

    Thanks. I have a problem though. I installed the jdk 1.1.8 because I heard that was the last one supported using Visual J++. Hence I have a C:\jdk1.1.8. This folder has no JRE subfolder so I am stuck at what you said the Classpath should contain as the path\folder you say it should be does not exist.
    I have a folder C:\Program Files\JavaSoft\JRE\1.3.1 which has the lib folder containing rt.jar.
    So as you can see I'm sort of in a quandry.
    If I make JAVA_HOME as you say then it does not contain the JRE. If I make JAVA_HOME C:\Program Files\JavaSoft so that your suggestion for Classpath is correct that folder does not contain the jrk and it seems that I will not be using it.
    Any suggestions how to set this up so that it's right?
    George Hester

  • How to set the View instance and view  attribute to lov field ?

    Hi
    I created lov and textfield programatically.
    I want to set the viewattribute and view instance to that items(lovbean, texfieldbean).
    How to set programatically?
    Thanks in Advance
    Awadesh

    Hi
    Thanks. Its working fine. But now i got some another issue.
    after setting, i put simple system.out.println(Pagecontext.getparameter("idoflov"));
    But it returns null value.
    why. Actully i want to pass this value (according to my requirement).
    The view instance and view attribute are setting correctly. But after that i checked means it returns null value .
    plz let me know.
    Thanks

  • How to set a value on a hidden required input field.

    I have a form that I need to set a value that is stored within the session onto it. I would like the input field to be hidden when a new row is created and just set the value with a value that I have stored with sessionScope.
    Is this possible?
    Any help would be appreciated.

    Frank,
    I sure can access the session attribute. I just wasn't sure how to set it. Here is a snippet of my jsp
    <af:inputText value="#{bindings.Createdby.inputValue}"
    binding="#{backing_Project.inputText3}"
    id="inputText3">
    If I set the value="" attribute to be say value="#{sessionScope.userInfo.userId}" then how does ADF know to update the CreatedBy column? This is where I got confused. I figured the value="#{bindings.Createdby.inputValue}" had to stay that way in order for the column to be updated correctly.
    Basically what I am wanting is to programatically set the userId of the person who is creating the row into the CreatedBy column and then show the user's readonly name when a user edits an existing row.
    Any help would be greatly appeciated.
    Marty

Maybe you are looking for

  • Please Help! Drag and drop does not work in Adobe AIR 3.1 (FlashBuilder 4.6)

    I am working on a PC is made of air and flashbuilder 4.6. Drag and drop application does not work in Flash Builder 4.6. However, the same source will work with Flash Builder 4.5. Please help me. <?xml version="1.0" encoding="utf-8"?> <s:WindowedAppli

  • SIS updation

    Hi experts, I am facing 2 error while updating the SIS. 1st Error- I have made all the necessary configuration in OVRO, OVRA. Assigned all the statistics group to the Order type, item cat,dly type etc. But when i am running the standard analuses repo

  • Junos Pulse 4.0 not working in Windows 8.1

    Hi, anyone got a Junos Pulse 4.0 release version working on 8.1? After the upgrade from 8 to 8.1 both my Cisco VPN client and Junos Pulse client stopped working because of resp. a yellow triangle for the Deterministic Network Enhancer and the Juniper

  • Geotagging with Google plugin.  Does it work?

    I've just bought a little gps receiver, and I'm trying to geotag some pix. I've loaded up the Google LR geotagger plugin (http://code.google.com/p/geotag-lightroom-plugin/), and I have a gpx file with the coordinates. I tell it to geotag the photos,

  • After update to v17 Firefox freezes

    After an automatic update to version 17.0.1, whenever a web page is selected it "freezes" on that page, only way to get out of Firefox is to go to task manager and stop program.