#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2002
    Posts
    596
    Rep Power
    23

    ant error: unable to find a javac compiler


    I was using ant 1.5 with no problems until recently...then upgraded to 1.6 and had all sorts of problems so have gone back to 1.5. Now I get the error:
    Code:
    ...unable to find a javac compiler:
    com.sun.tools.javac.Main is not on the classpath.
    Perhaps JAVA_HOME does not point to the JDK
    (JAVA_HOME is correct) when trying to compile anything. I've read a ton of posts about this, all of which say to copy tools.jar into $ANT_HOME/lib - I've done that and still got the problem. Any ideas?

    TIA
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2004
    Posts
    1
    Rep Power
    0

    also unable to find a javac compiler


    unable to find a javac compiler

    I have a similar problem using Ant 1.6 on Windows.

    This is unfortunately not a solution to your question.

    I have a similar problem to yours so when you find out the answer I'd like to know what it is!

    (I also tried the kludgey fix of copying tools.jar to %ANT_HOME%\lib but that didn't work.)

    John (September 26th 2004)
    ----
    The command I was using was 'ant doc', within a directory containing a build.xml file.

    In the original ant.bat, the following statement was being used:

    "%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% -lib "%CLASSPATH%" %ANT_CMD_LINE_ARGS%

    Maybe the setting of classpath by -classpath "%ANT_HOME%\lib\ant-launcher.jar"
    was the problem.

    I modified ant.bat to be as simple as possible. This resulted in a statement close to the manual-recommended minimal statement:-

    java -Dant.home=c:\ant org.apache.tools.ant.launch.Launcher

    When I ran this, at least I didn't get a NullPointerException error as the Launcher and Main were found and ran OK.

    My environment variables are
    %ANT_HOME%\lib\ant.jar;%ANT_HOME%\lib\ant-launcher.jar included in CLASSPATH
    %ANT_HOME%\bin included in PATH]

    ----

    However, now when build.xml gets to the property
    <javac srcdir="${src}"
    destdir="${build}"
    excludes="**/*.java.*"
    />


    Then this error is shown:-
    init:

    prepare:

    compile:
    [javac] Compiling 3 source files to C:\JimDemo\Pets02\build
    BUILD FAILED
    c:\JimDemo\pets02\build.xml:30: Unable to find a javac compiler;
    com.sun.tools.javac.Main is not on the classpath.
    Perhaps JAVA_HOME does not point to the JDK


    ----

    The main statement in the ant.bat file is :-
    "%_JAVACMD%" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% %ANT_CMD_LINE_ARGS%

    If I specify classpath after Launcher in the above statement,

    "%_JAVACMD%" %ANT_OPTS% -classpath "%ANT_HOME%\lib\ant-launcher.jar" "-Dant.home=%ANT_HOME%" org.apache.tools.ant.launch.Launcher %ANT_ARGS% -lib "%CLASSPATH%" %ANT_CMD_LINE_ARGS%

    in order to get %JAVA_HOME%\bin on the classpath, then I get a NullPointerException error due to not being able to find Launcher.

    I get the same error (NullPointerException) if -lib %JAVA_HOME%\bin is placed after Launcher in the above statement instead of -lib "%CLASSPATH%.
    ----
  4. #3
  5. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    Are you using ANT in eclipse by chance? If so, Ant fails this way because by default Eclipse uses the first Java.exe it finds to start with, and for some reason Eclipse/ANT look for javac.exe in this same location. If you look, there is a java.exe in the windows.system32 folder. To fix it I had to make the sdk path (c:\j2sdk1.4.2_04\bin;) the first thing in my PATH statement, before the window/system32 entry.

    I am using Eclipse 2.1, so this may not be your issue.

    EDIT: here are some other possible solutions
    http://www.mjwall.com/node/view/134
    Last edited by Nemi; September 27th, 2004 at 06:44 PM.
    ~Nemi

    Before posting did you try:
    [ Javadocs | Google ]
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2002
    Posts
    596
    Rep Power
    23
    Originally Posted by Nemi
    Are you using ANT in eclipse by chance? If so, Ant fails this way because by default Eclipse uses the first Java.exe it finds to start with, and for some reason Eclipse/ANT look for javac.exe in this same location. If you look, there is a java.exe in the windows.system32 folder. To fix it I had to make the sdk path (c:\j2sdk1.4.2_04\bin the first thing in my PATH statement, before the window/system32 entry.

    I am using Eclipse 2.1, so this may not be your issue.

    EDIT: here are some other possible solutions
    http://www.mjwall.com/node/view/134
    nope, I'm trying to use ant on the command line - in fact, I can use it OK from within netbeans, which I think has it's own version of ant bundled within it...
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2004
    Posts
    1
    Rep Power
    0

    Lightbulb


    This happened to me too when Jetty was trying to compile JSP files within a web application.
    I was running jetty through the command line and you'll found out that this will solve your problem:

    [Window]
    set PATH=%ANT_HOME%\bin;%JAVA_HOME%\bin;%PATH%

    [UNIX]

    PATH=$ANT_HOME/bin:$JAVA_HOME/bin:$PATH

    Good Luck

IMN logo majestic logo threadwatch logo seochat tools logo