Como executar um programa Java a partir de um script Unix?

0

Eu tento compilar um projeto Java a partir de um script do Linux, run_nmc_engine.sh . O problema é que recebo um erro ao iniciá-lo:

Error: Could not find or load main class caos.aaai.CaosNMCEngine

O comando que eu lancei no meu script era, mais ou menos,

java -Xmx${MAXMEM} -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar caos.aaai.CaosNMCEngine blablabla ...

Eu não adicionei tudo porque achei que o erro estava relacionado à primeira parte do comando. Eu não sei onde JCHEM é, mas sei que é

An implementation for chemical representation, search, storage, structural and non-structural data management functions. from ChemAxon website

Parece que não é possível encontrar onde está o arquivo CaosNMCEngine.java. No entanto, achei que estava bem colocado na pasta:

Vocêpodeencontrartodooprojetoem a página do projeto no GitHub . Deixe-me saber se você precisar de mais alguma coisa para completar o readme. Talvez você tenha mais sorte em comparar o script com o do projeto original .

O script completo é:

JCHEM=/Applications/ChemAxon/JChem-5.7.0
MAXMEM="2G"
if [[ 'uname -a | grep Linux' ]] ;
then
JCHEM=/gpfs/home/aheifets/opt/jchem-5.7.1
MAXMEM="8G"
fi

TOP='cd $(dirname $0)/../..; pwd -P'
PATH=$PATH:${JCHEM}/bin

# rm ReactorDemo.class
# javac -cp .:/Applications/ChemAxon/JChem-5.7.0/lib/jchem.jar -Xlint:unchecked ReactorDemo.java
# java -cp .:/Applications/ChemAxon/JChem-5.7.0/lib/jchem.jar ReactorDemo $1 $2 $3 #| tee /dev/stderr | mview - &

#rm RetroTests.class
#javac -cp .:/Applications/ChemAxon/JChem-5.7.0/lib/jchem.jar -Xlint:unchecked RetroTests.java
#java -cp .:/Applications/ChemAxon/JChem-5.7.0/lib/jchem.jar RetroTests $1 $2 $3 #| tee /dev/stderr | mview - &

date
#java -Xmx2G -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar caos.aaai.CaosEngine ${TOP}/data/cleaned_reaction_library_JChem_5.7.0_DISABLED  ${TOP}/data/SML ${TOP}/data/33.smiles 8000 0 ${TOP}/data/BENCHMARK/PROBLEMS/GlobalRXNs ${TOP}/data/BENCHMARK/PROBLEMS/GlobalSML

#java -Xmx2G -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar caos.aaai.CaosEngine ${TOP}/data/BENCHMARK/PROBLEMS/3/RXNs  ${TOP}/data/BENCHMARK/PROBLEMS/3/SML ${TOP}/data/BENCHMARK/PROBLEMS/3/goal_d3.smarts 1 0 ${TOP}/data/BENCHMARK/PROBLEMS/GlobalRXNs ${TOP}/data/BENCHMARK/PROBLEMS/GlobalSML

#PROBLEM=16
# for PROBLEM in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 18.1 19 20
#for PROBLEM in 11  #8 10 11 12 #1 12 14 15 16 #15 #11 12 14 16 18 19 8 9
for PROBLEM in 2
do
OUTDIR=rxndebug #exhaust #
mkdir -p ${TOP}/out/${OUTDIR}/${PROBLEM}
LOG=${TOP}/out/${OUTDIR}/${PROBLEM}/log
ERR=${TOP}/out/${OUTDIR}/${PROBLEM}/err

echo "==================================PROBLEM ${PROBLEM}=================================="
echo "==================================PROBLEM ${PROBLEM}==================================" > ${LOG}
echo "==================================PROBLEM ${PROBLEM}==================================" > ${ERR}
date
date > ${ERR}
#java -Xmx${MAXMEM} -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar test.ReactorDemo2 $*
#java -Xmx${MAXMEM} -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar caos.aaai.OperatorLibrary

#java -Xmx${MAXMEM} -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar caos.aaai.CaosEngine ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/RXNs  ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/SML ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/goal.smiles 10000 0 ${TOP}/data/BENCHMARK/PROBLEMS/GlobalRXNs_DISABLED ${TOP}/data/BENCHMARK/PROBLEMS/GlobalSML >${LOG} 2>${ERR}

java -Xmx${MAXMEM} -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar caos.aaai.CaosNMCEngine ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/RXNs_DISABLED  ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/SML ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/goal.smiles 10000 0 ${TOP}/data/BENCHMARK/PROBLEMS/GlobalRXNs ${TOP}/data/BENCHMARK/PROBLEMS/GlobalSML >${LOG} 2>${ERR}

#java -Xmx${MAXMEM} -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar caos.aaai.CaosEngine ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/RXNs  ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/SML ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/goal.smiles 5 0 ${TOP}/data/BENCHMARK/PROBLEMS/GlobalRXNs ${TOP}/data/BENCHMARK/PROBLEMS/GlobalSML EXHAUSTIVE >${LOG} 2>>${ERR}

#java -Xmx${MAXMEM} -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar caos.aaai.CaosEngine ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/RXNs  ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/SML ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/subgoals/goal_c.smiles 100 0 ${TOP}/data/BENCHMARK/PROBLEMS/GlobalRXNs ${TOP}/data/BENCHMARK/PROBLEMS/GlobalSML
#java -Xmx${MAXMEM} -cp .:${TOP}/build:${JCHEM}/lib/jchem.jar caos.aaai.CaosEngine ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/RXNs  ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/SML ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/subgoals/solution_B.smiles 100 0 ${TOP}/data/BENCHMARK/PROBLEMS/GlobalRXNs ${TOP}/data/BENCHMARK/PROBLEMS/GlobalSML
diff -b $LOG ${TOP}/data/BENCHMARK/PROBLEMS/${PROBLEM}/SOLUTION.txt

date
date >> ${ERR}
echo ${LOG}
done
    
por ThePassenger 09.05.2018 / 16:42

1 resposta

0

1) java está realmente procurando um .class nesse ponto, não um .java .

2) Se o .class que você possui for denominado caos.aaai.CaosEngine , então java procurará caos/aaai/CaosEngine.class (ou seja, dois diretórios abaixo) em cada diretório ou o JAR será adicionado ao caminho da classe.

Geralmente, é mais fácil empacotar todas as classes em um JAR, com o arquivo MANIFEST.MF do JAR com uma entrada Main-Class: classname apontando para a classe main() e, em seguida, iniciar o aplicativo usando java -jar {the_jar}

    
por 09.05.2018 / 17:40