0

I have an ant project in a directory which has 2 directories: bin and src and two files build.xml and script.sh.

The script.sh has the command:

time java SomeTestClass

where SomeTestClass is a class in bin. The bash script is executed in build.xml using the following:

<target name="run">
    <exec executable="/bin/bash">
            <arg value="script.sh"/>
    </exec>
</target>

However when I build using ant I get an error:

[exec] Error: Could not find or load main class SomeTestClass

How can I have the bash script see the java class SomeTestClass? I tried adding ./bin/SomeTestClass in the bash script, but the error changed to:

Error: Could not find or load main class ..bin.SomeTestClass
Cauchy
  • 1,677
  • 2
  • 21
  • 30

2 Answers2

1

use this script:

 time java -cp bin SomeTestClass
Nikita Skvortsov
  • 4,768
  • 24
  • 37
0

The issue is in calling SomeTestClass. Several options here:

  1. You must ensure that you add the location of your .class file to your classpath. So, if its in the current folder then add . to your classpath
  2. If the class is in a package thepackagename - it must be called with its fully-qualified name:

java -classpath . thepackagename.TheClassName Please, read the fcomplete guide: Error: Could not find or load main class

Community
  • 1
  • 1
Ivan Pronin
  • 1,768
  • 16
  • 14