0

I have a problem with a batch script that runs a java program, here some key lines of the script:

exeFinder="java -client -classpath './classes:./lib/javacsv.jar' -Xmx7200m Finder.Main ";
runFinder() {
    cleanFolders;
    $exeFinder $1 $2 $3 > $4;
}
dbName=$1;
k=$2;
n=$3;
outFile="simple_tester-out.log";

runFinder $dbName $k $n $outFile;

I run the script with its arguments: ./myScript.sh testing_7x8.csv 7 8
And I get this:

Error: Could not find or load main class Finder.Main

It looks like a java problem, so I change the line $exeFinder $1 $2 $3 > $4; for echo "$exeFinder $1 $2 $3 > $4"; to get my execution line:

java -client -classpath './classes:./lib/javacsv.jar' -Xmx7200m Finder.Main  testing_7x8.csv 7 8 > simple_tester-out.log

And it works like a charm! So I don't know what is happening.

I have checked some questions like this and this, but I can't see anything useful for me.

Thanks for your time, guys

2
  • sounds like a working directory vs classpath issue to me. whats the working directory the java process is run in? given that wd, are "./classes" and "./lib/javacsv.jar" valid paths? Commented Mar 9, 2016 at 19:42
  • yes, they are valid, I'm using the same directory for run the script and for run the "direct way" typing java - client -clas..... directly on the terminal. and the last form works fine. BTW, I have found the problem, or at least a solution. Commented Mar 9, 2016 at 20:30

2 Answers 2

1

It was a little problem with the simple quotes in the execution variable, so instead of:

"java -client -classpath './classes:./lib/javacsv.jar' -Xmx7200m Finder.Main "

it must be:

"java -client -classpath ./classes:./lib/javacsv.jar -Xmx7200m Finder.Main "

It is probably something related with bash and how it works, I don't know enough to explain why this happens, but that change solved the problem.

Sign up to request clarification or add additional context in comments.

Comments

0

Try sh $exeFinder $1 $2 $3 > $4;

In my testing, I was unable to directly execute a command in a variable, but I could pass it to sh.

2 Comments

this didn't work for me, please notice that $exeFinder is a variable that starts with java -client..... so it is like type in the console sh java -classpath.... which make no sense to the console, in fact, it returns sh: 0: Can't open java
Ah, yeah, that makes sense. I only got as far as testing running a basic command (cd ..) from a variable, and assumed that was the problem when it didn't work for me (and running via sh $variable did). Glad you did find the answer :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.