gpt4 book ai didi

java - 通过 Linux : Could not find or load main class 执行 Java 时遇到问题

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:13:43 26 4
gpt4 key购买 nike

<分区>

我正在尝试从 Linux 运行 java 代码并遇到错误“错误:无法找到或加载主类”。我在“/home/user/test/comp/code”目录中有主要代码“CompareTableCachedRows.java”,我能够成功编译和创建“CompareTableCachedRows.class”但是当我试图通过java命令运行它时使用shell脚本给出错误。尝试使用类路径变量,但没有帮助。任何帮助将不胜感激。

我在“/home/user/test/comp/code”目录中有主要代码“CompareTableCachedRows.java”,我能够成功编译并创建“CompareTableCachedRows.class”但是当我试图通过java运行它时使用 shell 脚本的命令会出错。尝试使用类路径变量,但没有帮助。任何帮助将不胜感激。

#!/bin/ksh

CONFIG_DIR="/home/user/test/comp/code/CustomJobs/configs"
INPUT_DIR="/home/user/test/comp/code/CustomJobs/inputs"

TBL_FILE=$CONFIG_DIR/MASTER-LIST.sql
INFILE=$INPUT_DIR/firm-cases.txt


OB="CompareTables"
JOBCLASS="AcctExtract"

# DEV2:
ACCT_SVR_JDBC1="actdev2db.nam.nsroot.net:7096/ActDbAct?DYNAMIC_PREPARE=false&ENCRYPT_PASSWORD=true&SQLINITSTRING=set quoted_identifier off"
# DEV3:
ACCT_SVR_JDBC2="oraasgtd46-scan.nam.nsroot.net:8889/DEV"


LEFTDB=SYBASE
RIGHTDB=ORACLE

ACCT_USER1=xxxx
ACCT_PSWD1=xxxx

ACCT_USER2=yyyy
ACCT_PSWD2=yyyy


LOGDIR="/home/user/test/comp/temp"

WORKFILE=$INFILE
LOGFILE=$LOGDIR/tbl_compare.log
COMPARE_FILE=$LOGDIR/tbl_compare.csv

echo Account Address Uploading
echo Original INFILE is $INFILE
echo LOGFILE is $LOGFILE
rm -f $LOGFILE

echo Original INFILE is $INFILE > $LOGFILE

DAILYBTCH_INSDIR="/home/user/test/comp/code/CustomJobs/"
lib_dir="/home/user/test/comp/lib"
classes_dir="$DAILYBTCH_INSDIR/bin"


CLASSPATH=${classes_dir}

for f in \
${lib_dir}/ojdbc7-12.1.0.2.jar \
${lib_dir}/jconn4.jar \
${lib_dir}/EccpressoFIPS.jar \
${lib_dir}/EccpressoFIPSJca.jar
do
CLASSPATH="${CLASSPATH};$f"
done


export CLASSPATH

java_bin="/export/opt/jdk/1.7.0_45l64/bin"
java_options="-Xms128m -Xmx256m -Djava.awt.headless=true"
main_class="/home/user/test/comp/code/CompareTableCachedRows"

echo ""
echo "==================================="
echo "Classes Dir : ${classes_dir}"
echo "Source Dir : `pwd`"
echo "Java bin dir : ${java_bin}"
echo "Java options : ${java_options}"
echo "Java main class : ${main_class}"
echo "Java lib dir : ${lib_dir}"
echo "Java Classpath : ${CLASSPATH}"
echo "DB Host-Port-1: ${ACCT_SVR_JDBC1} "
echo "DB Host-Port-2: ${ACCT_SVR_JDBC2} "
echo "DB User : ${ACCT_USER}"
echo "==================================="

echo "===================================" >> $LOGFILE
echo "Classes Dir : ${classes_dir}" >> $LOGFILE
echo "Source Dir : `pwd`" >> $LOGFILE
echo "Java bin dir : ${java_bin}" >> $LOGFILE
echo "Java options : ${java_options}" >> $LOGFILE
echo "Java main class : ${main_class}" >> $LOGFILE
echo "Java lib dir : ${lib_dir}" >> $LOGFILE
echo "Java Classpath : ${CLASSPATH}" >> $LOGFILE
echo "DB Host-Port-1: ${ACCT_SVR_JDBC1} " >> $LOGFILE
echo "DB Host-Port-2: ${ACCT_SVR_JDBC2} " >> $LOGFILE
echo "DB User : ${ACCT_USER} " >> $LOGFILE
echo "===================================" >> $LOGFILE


java ${java_options} -cp "/home/user/test/comp/lib/*" /home/user/test/comp/code/CompareTableCachedRows.class \
-tblListFile $TBL_FILE \
-inputFile "${WORKFILE}" \
-dbHostPort1 "${ACCT_SVR_JDBC1}" \
-dbHostPort2 "${ACCT_SVR_JDBC2}" \
-dbType1 Sybase \
-dbType2 Oracle \
-dbUsr1 "${ACCT_USER1}" -dbPw1 "${ACCT_PSWD1}" \
-dbUsr2 "${ACCT_USER2}" -dbPw2 "${ACCT_PSWD2}" \
-asUsr "${ACCT_USER}" >> $LOGFILE 2>&1

errcode=$?

echo "#####################"
echo "Finished $0 at `date`"
echo "#####################"

echo "Finished $0 at `date`" >> $LOGFILE

grep -E '^#' $LOGFILE | sed -e "s/^#LEFT/${LEFTDB}/" -e "s/^#RIGHT/${RIGHTDB}/" -e "s/^#ONLY-IN-LEFT/ONLY-IN-${LEFTDB}/" -e "s/^#ONLY-IN-RIGHT/ONLY-IN-${RIGHTDB}/" \
-e "s/LEFT=/${LEFTDB}=/" -e "s/RIGHT=/${RIGHTDB}=/" > $COMPARE_FILE

exit $errcode

我期望此脚本使用作为参数传递的表列表和其他配置文件来执行“CompareTableCachedRows.class”中的主要代码。

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com