com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK

  • Thread starter Miss Michelle. Heigardt
  • Start date
M

Miss Michelle. Heigardt

Hallo newsgroup, I am getting the error

com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK

JAVA_HOME does point to my JDK. My Tomcat works with no problem. My
Apache2 works with no problem. But I cannot compile. I am logged onto a
free Debian 3.1 system as root. You can see at the bottom I am using
Java 1.4 and both java and javac can be run from the command line
without problem. Searching in Google there are lots of talk on
tools.jar but I dont think this is for me as my Tomcat & Apache2 work.

What shall I look for now? What shall I do?
Thank you

Michelle




deb31Test:~/t9/v876/samples/jpetstore#echo $JAVA_HOME
/usr/local/lib/jdk
deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore# ls /usr/local/lib -l
total 16
drwxrwxr-x 9 root src 4096 Aug 27 01:51 j2sdk1.4.2_08
lrwxrwxrwx 1 root staff 28 Aug 27 01:55 jdk ->
/usr/local/lib/j2sdk1.4.2_08
drwxrwsr-x 3 root staff 4096 Jan 16 08:56 python2.3
drwxrwsr-x 3 root staff 4096 Jan 6 11:27 site_ruby
deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore# find / -name tools.jar -print
/usr/lib/j2se/1.4/lib/tools.jar
/usr/local/lib/j2sdk1.4.2_08/lib/tools.jar
deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore# ls -la
/usr/local/lib/j2sdk1.4.2_08/lib/tools.jar
-rw-r--r-- 1 root root 5092686 Jan 11 15:19
/usr/local/lib/j2sdk1.4.2_08/lib/tools.jar
deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore# ant build
Buildfile: build.xml

build:
[javac] Compiling 73 source files to
/t9/v876/samples/jpetstore/.classes

BUILD FAILED
/t9/v876/samples/jpetstore/build.xml:76: 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

Total time: 4 seconds

deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore# java -version
java version "1.4.2_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)


deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore#
deb31Test:~/t9/v876/samples/jpetstore# javac
Usage: javac <options> <source files>
where possible options include:
-g Generate all debugging info
-g:none Generate no debugging info
-g:{lines,vars,source} Generate only some debugging info
-nowarn Generate no warnings
-verbose Output messages about what the compiler is
doing
-deprecation Output source locations where deprecated
APIs are used
-classpath <path> Specify where to find user class files
-sourcepath <path> Specify where to find input source files
-bootclasspath <path> Override location of bootstrap class files
-extdirs <dirs> Override location of installed extensions
-d <directory> Specify where to place generated class
files
-encoding <encoding> Specify character encoding used by source
files
-source <release> Provide source compatibility with specified
release
-target <release> Generate class files for specific VM
version
-help Print a synopsis of standard options


The line in my build.xml says

<mkdir dir="${build.dir}"/>
<javac destdir="${build.dir}" source="1.4" target="1.4" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>
 
G

Gordon Beaton

com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK

JAVA_HOME does point to my JDK. My Tomcat works with no problem. My
Apache2 works with no problem. But I cannot compile. I am logged
onto a free Debian 3.1 system as root. You can see at the bottom I
am using Java 1.4 and both java and javac can be run from the
command line without problem. Searching in Google there are lots of
talk on tools.jar but I dont think this is for me as my Tomcat &
Apache2 work.

What do Tomcat and Apache have to do with it?

Regardless of what you think, you do need tools.jar in your classpath
if you want to use the compiler classes (not javac) from within your
java application (look for it in e.g. $JAVA_HOME/lib).

Read more here:
http://java.sun.com/developer/JDCTechTips/2003/tt0722.html

/gordon
 
M

Miss Michelle. Heigardt

Thank you for your reply Gordon.
What do Tomcat and Apache have to do with it?

They do show that my Java is not broken and Java works with other
applications without a problem.
Regardless of what you think, you do need tools.jar in your classpath
if you want to use the compiler classes (not javac) from within your
java application (look for it in e.g. $JAVA_HOME/lib).

I have read the online manual and it says that tools.jar is needed in
the classpath. And tools.jar is in my classpath (see it in my first
post with all the environment variables). This is why I do not
understand why it won't compile and write in this news group.

Thank you
Michelle
 
G

Gordon Beaton

I have read the online manual and it says that tools.jar is needed
in the classpath. And tools.jar is in my classpath (see it in my
first post with all the environment variables).

The only environment variable you show in your earlier post is
JAVA_HOME, not CLASSPATH. However it seems that Ant adds the necessary
tools.jar to your classpath if JAVA_HOME is set; perhaps you need to
export it as well if you haven't already done so.

/gordon
 
R

rsch

Hello !
com.sun.tools.javac.Main is not on the classpath.
Perhaps JAVA_HOME does not point to the JDK ....
<javac destdir="${build.dir}" source="1.4" target="1.4" debug="true"
deprecation="false" optimize="false" failonerror="true">
<src path="${src.dir}"/>
<classpath refid="master-classpath"/>
</javac>

If you are using ANT you must set JAVA_HOME.
So ANT will search the Java-compiler in $JAVA_HOME/lib/tools.jar.
Are you sure that JAVA_HOME is pointing to the Java SDK not to the JRE?
 
Joined
Nov 12, 2007
Messages
2
Reaction score
0
I faced the same problem. I created system variable by name JAVA_HOME and updated it with value c:\program files\java\jdk1.5.xxx . But yet I kept getting same error. I event checked it on command prompt if variable was set by typing echo %JAVA_HOME% and it showed me proper value. I played for a long time with eclipse class path, ant and other settings but no success. Finally age old remedy came to my rescue. I restarted my machine and it worked. @$@$% microsoft.
 
Joined
Oct 2, 2008
Messages
2
Reaction score
0
Same issue is resolved as per below

http : // www . drftpd.org / forums / viewtopic.php ? f=5&t=2978
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top