Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 22nd, 2004, 07:34 AM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 596 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 3 h 56 m 23 sec
Reputation Power: 22
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

Reply With Quote
  #2  
Old September 27th, 2004, 05:16 PM
JD1 JD1 is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 1 JD1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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%.
----

Reply With Quote
  #3  
Old September 27th, 2004, 06:41 PM
Nemi Nemi is offline
Clueless llama
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Feb 2001
Location: Lincoln, NE. USA
Posts: 2,353 Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level)Nemi User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Days 12 h 39 m 5 sec
Reputation Power: 116
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
__________________
~Nemi

Before posting did you try:
[ Javadocs | Google ]

Last edited by Nemi : September 27th, 2004 at 06:44 PM.

Reply With Quote
  #4  
Old September 29th, 2004, 03:43 AM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 596 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 3 h 56 m 23 sec
Reputation Power: 22
Quote:
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...

Reply With Quote
  #5  
Old October 16th, 2004, 07:05 AM
paulotaylor paulotaylor is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 1 paulotaylor User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation 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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > ant error: unable to find a javac compiler

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap