我有一个批处理文件转换成shell文件 批次代码是:
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
对于上面的代码,我编写了这个shell代码:
#!/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
当执行上面的代码时,它会给出错误:
错误:无法找到或加载主类 类路径= .home.bitsbridge.Videos.HomeHealthGrouper.dist.HomeHealthJava.jar:.home.bitsbridge.Videos.HomeHealthGrouper.dist.HH_PPS_V_API.jar
但是执行它时无法加载类路径中提到的jar文件并且它会给出错误:
Java(TM)SE运行时环境(版本1.7.0_80-b15)Java HotSpot(TM) 服务器VM(内置24.80-b11,混合模式)错误:无法找到或加载 主要班级 类路径= .home.Desktop.HPPP.HomeHealthGrouper.dist.HomeHealthJava.jar:.home.D esktop.HPPP.HomeHealthGrouper.dist.HH_PPS_V_API.jar
P.S:我已经检查了java路径。
这是 / 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"
请帮助找到问题。我被困在这里超过一周
我已经更新了上面提到的shell代码,并且在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=""
执行上述代码后的输出:
- ./ javaaad.sh java版" 1.7.0_80" Java(TM)SE运行时环境(版本1.7.0_80-b15) Java HotSpot(TM)服务器VM(内置24.80-b11,混合模式) 错误:无法找到或加载主类
收到错误
错误:无法找到或加载主类
答案 0 :(得分:0)
在类路径切换前添加连字符: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.
...
同时将java $JAVA_VERSION ...
更改为java ...
,因为现在变量$JAVA_VERSION
中存在空标记,导致额外参数java '' ...
。 java -version
不向stdr打印任何stdout和多行版本说明。