0
votes

I got a batch file to convert into shell file batch code is:

SETLOCAL

SET BASEDIR=C:\hhpps\HomeHealthGrouper
SET HH_CLASSPATH=.;%BASEDIR%\dist\HomeHealthJava.jar;.;%BASEDIR%\dist\HH_PPS_V_API.jar
rem SET JAVA_VERSION=-version:1.7
SET TEST_FILE=%BASEDIR%\TestData\TestDataV7118.txt

rem SET OPTIONS=details=1

java %JAVA_VERSION% -Xms512m -Xmx512m -Djava.util.logging.config.file="%BASEDIR%\config\logging.properties" ^
    -classpath "%HH_CLASSPATH%" com.mmm.cms.homehealth.test.HomeHealthGrouper_HP ^
    "input=%TEST_FILE%" "config=%BASEDIR%\config\HomeHealthGrouper.properties" ^
    %OPTIONS%

rem reset all variables to prevent locking
SET BASEDIR=
SET HH_CLASSPATH=
SET TEST_FILE=
SET OPTIONS=

 ENDLOCAL

For the above code i have written this shell code:

#!/bin/bash
export BASEDIR=/home/bitsbridge/Videos/HomeHealthGrouper
#export JAVA_HOME=/media    /bitsbridge/WIN XP/Program Files/Java/jdk1.6.0/bin/java
#export PATH=$PATH:/usr/java/jdk1.6.0/bin
#export JAVA_HOME
 export HH_CLASSPATH=.:$BASEDIR/dist/HomeHealthJava.jar:$BASEDIR/dist/HH_PPS_V_API.jar
#export CLASSPATH=${CLASSPATH}
classpath=""
input=""
config=""
export JAVA_VERSION=`java -version`                 #/usr/lib/jvm/java-7-oracle/
#temp="java -version"
#JAVA_VERSION=`java -version 2>&1 |awk 'NR==1{ gsub(/"/,""); print $3 }'`
export TEST_FILE=$BASEDIR/TestData/TestDataV6117.txt
export OPTIONS=1

  java $JAVA_VERSION -Xms512m -Xmx512m -Djava.util.logging.config.file="/home/bitsbridge/Videos/HomeHealthGrouper/config/logging.properties"\
            classpath="/home/bitsbridge/Videos/HomeHealthGrouper/dist/HomeHealthJava.jar:/home/bitsbridge/Videos/HomeHealthGrouper/dist/HH_PPS_V_API.jar"  com.mmm.cms.homehealth.test.HomeHealthGrouper_HP\
            input="/home/bitsbridge/Videos/HomeHealthGrouper/TestData/TestDataV6117.txt" config="/home/bitsbridge/Videos/HomeHealthGrouper/config/HomeHealthGrouper.properties"\
            $OPTIONS


 export BASEDIR=""
 export HH_CLASSPATH=""
 export TEST_FILE=""
  export OPTIONS=""

 #${CLASSPATH}:.
 #com.mmm.cms.homehealth.test.HomeHealthGrouper_HP

WHEN ABOVE CODE IS EXECUTED IT IS GIVING ERROR:

Error: Could not find or load main class classpath=.home.bitsbridge.Videos.HomeHealthGrouper.dist.HomeHealthJava.jar:.home.bitsbridge.Videos.HomeHealthGrouper.dist.HH_PPS_V_API.jar

But while executing it is not able to load the jar files mention in the classpath and it's giving the error:

Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) Server VM (build 24.80-b11, mixed mode) Error: Could not find or load main class classpath=.home.Desktop.HPPP.HomeHealthGrouper.dist.HomeHealthJava.jar:.home.D esktop.HPPP.HomeHealthGrouper.dist.HH_PPS_V_API.jar

P.S: I have already check the java path.

This is the content of /etc/environment/:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/$
JAVA_HOME="/usr/lib/jvm/java-7-oracle"

please help finding the problem.I am stuck here over a week

I have update the above mention shell code and code is issue free as checked at shellcheck.net:

 #!/bin/bash
 BASEDIR=/home/Desktop/HPPP/HomeHealthGrouper
 FILE=/home/Desktop/HPPP/HomeHealthGrouper/config/logging.properties

 export HH_CLASSPATH=.:/home/Desktop/HPPP/HomeHealthGrouper/dist/HomeHealthJava.jar:.:$BASEDIR/dist/HH_PPS_V_API.jar
 JAVA_VERSION="$(java -version)"            
 export JAVA_VERSION
 export TEST_FILE=$BASEDIR/TestData/TestDataV6117.txt
 export OPTIONS=1

 java "$JAVA_VERSION" -Xms512m -Xmx512m -Djava.util.logging.config.file="$FILE"\
 -classpath="/home/Desktop/HPPP/HomeHealthGrouper/dist/HomeHealthJava.jar:/home/Desktop/HPPP/HomeHealthGrouper/dist/HH_PPS_V_API.jar" com.mms.cms.homeHealth.test.HomeHealthGrouper_HP\
 "input=/home/Desktop/HPPP/HomeHealthGrouper/TestData/TestDataV6117.txt" "config=/home/Desktop/HPPP/HomeHealthGrouper/config/HomeHealthGrouper.properties"\
 $OPTIONS


 export BASEDIR=""
 export HH_CLASSPATH=""
 export TEST_FILE=""
 export OPTIONS=""

This the output after execution of above code:

  • ./javaaad.sh java version "1.7.0_80" Java(TM) SE Runtime Environment (build 1.7.0_80-b15) Java HotSpot(TM) Server VM (build 24.80-b11, mixed mode) Error: Could not find or load main class

Getting an error:

Error: Could not find or load main class

1
Couldn't find what the problem is.. Run the script thru [ shellcheck ]sjsam
I am not sure what the downvote is for. Downvoting without a reasonable comment doesn't help. :-( imhosjsam
thanks for the website.There is little bit structure change.Hope it works thanks sjsammkp24
even I don't know the reason for downvote.mkp24
@mpk24 Hmm. If you're new to bash then shellcheck is an invaluable tool. Also feel free to use bash -x to debug your scripts. Good luck :-)sjsam

1 Answers

0
votes

Add hyphen in front of classpath switch: classpath=... => -classpath=....

java -h
...
-classpath <class search path of directories and zip/jar files>
              A : separated list of directories, JAR archives,
              and ZIP archives to search for class files.
...

Also change java $JAVA_VERSION ... to java ... because now you have empty sting in variable $JAVA_VERSION causing extra argument java '' .... java -version prints nothing to stdout and multiline version description to stderr.