I try to compile a Java project from a Linux script, run_nmc_engine.sh. The problem is that I get an error when launching it :

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

The command I launched in my script was, more or less,

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

I didn't add it all because I thought the error was in related to the first part of the command. I don't know where JCHEM is but I know it is

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

It seems it can't find where the CaosNMCEngine.java file is. Yet, I thought it was well placed in the folder :

enter image description here

You can find the whole project on the webpage of the project on GitHub. Let me know if you need anything more to complete the readme. Maybe you will have more luck comparing the script with the one from the original project.

The full script is :

if [[ `uname -a | grep Linux` ]] ;

TOP=`cd $(dirname $0)/../..; pwd -P`

# 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 - &

#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

# 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
OUTDIR=rxndebug #exhaust #
mkdir -p ${TOP}/out/${OUTDIR}/${PROBLEM}

echo "==================================PROBLEM ${PROBLEM}=================================="
echo "==================================PROBLEM ${PROBLEM}==================================" > ${LOG}
echo "==================================PROBLEM ${PROBLEM}==================================" > ${ERR}
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

date >> ${ERR}
echo ${LOG}
  • You may be better off asking on Stack Overflow under Java tag, as this is rather a niche Java question than a Linux specific question. – ajeh May 9 '18 at 15:11

1) java is really looking for a .class at that point, not a .java.

2) If the .class you have is named caos.aaai.CaosEngine then java looks for caos/aaai/CaosEngine.class (ie, two directories down) in each directory or JAR added to the class path.

It is often simpler to packages all classes in a JAR, with the MANIFEST.MF file of the JAR having an Main-Class: classname entry pointing to the main() class, and then start the app using java -jar {the_jar}

|improve this answer|||||
  • thank you for your answer. Unfortunately I only have CaosEngine.java in caos/aaai I never did a JAR nor a MANIFEST.MF I only took the code from the last link I provided and try to modify it on my own to run my own class – Revolucion for Monica May 9 '18 at 15:55
  • Then you have to compile the java to get a .class from a .java. You use the Java compiler (javac command) or use an IDE. A JAR is mostly a ZIP file, the command to create JARs is jar (or ask the IDE to generate it). But this is StackExchange territory (or Java 101...). – xenoid May 9 '18 at 20:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.