0

I have a small script in rhel6 that basically goes like this:

#!/bin/bash

if [ "$JAVA_HOME" = "" ]; then
    echo The environment variable JAVA_HOME is not set.  Deploy failed.
    exit 1
else
    CLASSPATH=./lib/ant-nodeps.jar:./lib/ant.jar:./lib/ant-launcher.jar:./lib/tools.jar 

    #echo classpath: $CLASSPATH
    "$JAVA_HOME/bin/java" -Dant.home=./ant org.apache.tools.ant.launch.Launcher -Dinstaller.requested=false  -buildfile deploy.xml 
fi

I have tried many things and i still get this launcher not found error. ant version -1.9.9

In .bash_profile

PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.41.x86_64/jre/bin/:/opt/WebSphere/AppServer/java/bin:/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin:/root/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/usr/bin/mozilla:/usr/bin/firefox:/usr/local/apache-ant-1.9.9/bin:/bin/bash:/usr/bin/java:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.41.x86_64/jre/bin/:/opt/WebSphere/AppServer/java/bin:/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin:/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.41.x86_64/bin:/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin:/usr/local/apache-ant-1.9.9/lib/ant-launcher.jar

JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.41.x86_64
ANT_HOME=/usr/local/apache-ant-1.9.9

I have also tried setting ANT_LIB in bash_profile but with no luck..What can i do next??

The error is : Error: Could not find or load main class org.apache.tools.ant.launch.Launcher

Maya
  • 1
  • 4

1 Answers1

0

Your classpath contains relative paths as indicated by the dot in ./lib/ant.jar

CLASSPATH=./lib/ant-nodeps.jar:./lib/ant.jar

The dot means "here", if you are at your home directory, that's /home/[your username]. You should also add the classpath var to the command:

$JAVA_HOME/bin/java -cp $CLASSPATH ...

You can fix in several ways

  1. Add to the script a cd /some/dir to the path were /lib/ant.jar is
  2. Build the CLASSPATH var using absolute paths.
  3. Verify that classpath is correctly set in build.xml if that's the case.

workaround: Run the script from the path were /lib/ant.jar is.

LMC
  • 10,453
  • 2
  • 27
  • 52
  • Luis, The directory where the script is does have lib directory with those ant jars. This is an older script that used to run in windows that im converting for linux. I have tried adding -cp argument, adding absolute paths of ant jars from ant 1.9.9 as well but nothing worked. This does work in windows though even script has same structure with those jar files from lib directory added to classpath but actual ant version installed and being used is completely different. – Maya Apr 02 '17 at 16:42
  • I have added an item to my answer. Also please update your question with the exact error you are getting. – LMC Apr 03 '17 at 13:37
  • I don't think the build file has classpath set.. I will try that. ty – Maya Apr 04 '17 at 22:28