简体   繁体   中英

set up DERBY_HOME environment variable on Windows 10

I'm trying to configure my system to allow for Java DB/derby.

I changed the JAVA_HOME environment variable through Advanced system settings of the Control Panel by following the tutorial on this website .

I opened the command prompt to run setEmbeddedCP.bat with following command line:

c:\Program Files\Java\jdk1.8.0_60\db\bin>setEmbeddedCP.bat

And this was the output:

DERBY_HOME or DERBY_INSTALL not set. Set one of these variables
to the location of your Derby installation.

I'm searching online for answers. I'm not sure if I should open the bat file directly and change the variables in that file or go through Advanced system settings again. Any insight would be greatly appreciated.

@rem set DERBY_INSTALL=%JAVA_HOME%\db

@if "%DERBY_HOME%"=="" set DERBY_HOME=%DERBY_INSTALL%
@if "%DERBY_HOME%"=="" goto noderbyhome

@FOR %%X in ("%DERBY_HOME%") DO SET DERBY_HOME=%%~sX

set CLASSPATH=%DERBY_HOME%\lib\derby.jar;%DERBY_HOME%\lib\derbytools.jar;%DERBY_HOME%/lib/derbyoptionaltools.jar;%CLASSPATH%
@goto end

:noderbyhome
@echo DERBY_HOME or DERBY_INSTALL not set. Set one of these variables
@echo to the location of your Derby installation.
@goto end

:end

The third command line of setEmbeddedCP.bat checks if environment variable DERBY_HOME is defined which is not the case in your environment resulting in getting the error message output.

The second command line assigns value of environment variable DERBY_INSTALL to variable DERBY_HOME if DERBY_HOME is not defined.

The first line would define the variable DERBY_INSTALL with path to subdirectory db in directory of Java , but this line is commented out because of command rem .

So with Derby installed in subdirectory db of Java directory all you need to do use removing the command rem and the space after this command.

By the way: This batch file is coded ugly. Better would be:

@echo off

rem Define installation directory of Derby which is by default the
rem subdirectory "db" in directory of Java. Modify this line if the
rem files derby.jar, derbytools.jar and derbyoptionaltools.jar are
rem not installed into subdirectory "db\lib" of the Java directory.
rem Altenatively the environment variable DERBY_HOME can be defined
rem with path to main directory of Derby installation to use.

set "DERBY_INSTALL=%JAVA_HOME%\db"

if "%DERBY_HOME%"=="" set "DERBY_HOME=%DERBY_INSTALL%"
if "%DERBY_HOME%"=="" (
    echo Error detected by %~f0:
    echo.
    echo DERBY_HOME or DERBY_INSTALL not set. Set one of these
    echo variables to the location of your Derby installation.
    echo.
    pause
    goto :EOF
)

rem Get directory path of DERBY in short 8.3 format.
for %%X in ("%DERBY_HOME%") do set "DERBY_HOME=%%~sX"

rem Define the class path with additional Derby Java archives.
set "CLASSPATH=%DERBY_HOME%\lib\derby.jar;%DERBY_HOME%\lib\derbytools.jar;%DERBY_HOME%\lib\derbyoptionaltools.jar;%CLASSPATH%"

It looks like batch file setEmbeddedCP.bat is in subdirectory bin of the Derby installation directory db in directory of Java .

Taking this fact into account, the batch file setEmbeddedCP.bat could determine installation respectively home directory of Derby by itself with two simple lines at top of the batch file instead of line with command set .

@echo off

rem Define installation directory of Derby which is by default the
rem subdirectory "db" in directory of Java. This batch file is by
rem default in the subdirectory "bin" of the Derby directory "db".
rem Determine the Derby installation directory from directory of
rem this batch file.

set "DERBY_INSTALL=%~dp0"
set "DERBY_INSTALL=%DERBY_INSTALL:\bin\=%"

rem Altenatively the environment variable DERBY_HOME can be defined
rem with path to main directory of Derby installation to use.

if "%DERBY_HOME%"=="" set "DERBY_HOME=%DERBY_INSTALL%"
if "%DERBY_HOME%"=="" (
    echo Error detected by %~f0:
    echo.
    echo DERBY_HOME or DERBY_INSTALL not set. Set one of these
    echo variables to the location of your Derby installation.
    echo.
    pause
    goto :EOF
)

rem Get directory path of DERBY in short 8.3 format.
for %%X in ("%DERBY_HOME%") do set "DERBY_HOME=%%~sX"

rem Define the class path with additional Derby Java archives.
set "CLASSPATH=%DERBY_HOME%\lib\derby.jar;%DERBY_HOME%\lib\derbytools.jar;%DERBY_HOME%\lib\derbyoptionaltools.jar;%CLASSPATH%"

For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

  • echo /?
  • for /?
  • got /?
  • if /?
  • pause /?
  • rem /?
  • set /?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM