GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Javac error... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Javac error..." Watch "Javac error..." New topic
Author

Javac error...

Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
I have set the path and even then I am getting the following error.

<<<<<<<<<<<<<<< Starts here >>>>>>>>>>>>>>


C:\>path=C:\oracle\Ora_Client\bin\;C:\Program Files\Oracle\jre\1.1.8\bin\;C:\WIN
DOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Rational\Clea
rCase\bin;C:\Program Files\Documentum\Shared\;C:\Program Files\Java\j2re1.4.2_08
\bin;C:\Program Files\Rational\common;C:\Program Files\Rational\ClearQuest;;C:\P
rogram Files\Java\j2re1.4.2_08\bin;C:\Program Files\apache-ant-1.6.5\bin;CATALIN
A_HOME=C:\JBuilderX\thirdparty\jakarta-tomcat-4.1.27-LE-jdk14\bin;C:\j2sdk1.4.2_
08\bin;;c:\jesdk1.4.2_08\bin;;c:\jesdk1.4.2_08\bin;

C:\>javac
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/Main


<<<<<<<<<<ends here>>>>>>>>>>>>>

if I compile like

c:\jesdk1.4.2_08\bin\javac Test1.java

it is compiling.

Appreciate help and thanks in advance


Srini
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Puthriah

You don't need PATH variable here. You need to set the CLASSPATH variable properly for class not found errors.

PATH will allow you find "javac" command from anywhere if you have the corresponding folder in the PATH (in your case it would be c:\j2sdk1.4.2_08\bin). The error you are getting is due to the CLASSPATH.

Also, I am not sure why you get NoClassDefFoundError, as that should not happen during compilation. This error can be thrown when you run 'java' not 'javac'.

Anyways, you need to have PATH set as,


I rearranged you path variable and removed unnecessary entries...

Also, see what CLASSPATH you have,
c:\>echo %CLASSPATH%

First you can set the path as I have suggested and then tell us the classpath setting on your machine.

Regards,
Maulin

[ September 19, 2005: Message edited by: Maulin Vasavada ]
[ September 21, 2005: Message edited by: Marilyn de Queiroz ]
Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
Hi Maulin

I did as you said.

I am getting the following message when I run javac. But when I run java it is OK.

Hereunder I am giving you the echo of classpath also.

Appreciate your help.

Thanks

H:\>javac
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
ain

H:\>echo %classpath%
;C:\JBuilderX\thirdparty\jakarta-tomcat-4.1.27-LE-jdk14\bin;C:\Program Files\Jav
a\j2re1.4.2_08\lib;C:\j2sdk1.4.2_08\lib;

H:\>
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

This is interesting -- it looks like someone / something has moved the tools.jar file (or it is corrupt). Search for tools.jar and see where it is -- that is needed to run the javac tool.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

Originally posted by Maulin Vasavada:
Also, I am not sure why you get NoClassDefFoundError, as that should not happen during compilation. This error can be thrown when you run 'java' not 'javac'.


That's because javac uses java to do the compilation. One of the .class files that javac needs is either corrupt or is the wrong version or something. You get NoClassDefFounds when the class that you are loading can be found, but a dependant class is not. Of course, the message doesn't tell you which dependency is causing the problem. ClassNotFound simply means that the class you are loading cannot be found.
Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
tools.jar is under
C:\j2sdk1.4.2_08\lib.
Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
Pl analyze the following actions:

1) using java comand..OK

2) using javac command.. not OK

3) using javac command with a java file ... not OK

4) using javac command with the javac file path for a java file... OK




<<<<<<<<<<<<<< start of command line results>>>>>>>>>>>>>>>>>>>>>>
C:\temp>java
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A ; separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions

C:\temp>javac
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
ain

C:\temp>javac test1.java
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
ain

C:\temp>c:\j2sdk1.4.2_08\bin\javac test1.java

C:\temp>


<<<<<<<<<<<<<< end of command line results>>>>>>>>>>>>>
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi

look for all tools.jar file on your machine. Not just one in the lib folder yo u are seeing...

This looks like some environment issue.

Regards
Maulin
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061


I rearranged you path variable and removed unnecessary entries...

Also, see what CLASSPATH you have,
c:\>echo %CLASSPATH%

First you can set the path as I have suggested and then tell us the classpath setting on your machine.

Regards,
Maulin

[ September 19, 2005: Message edited by: Maulin Vasavada ][/qb]<hr></blockquote>

Actually, you DO need the PATH variable, but you DO NOT need the CLASSPATH variable at this point. However, it looks like you have other software installed that uses the java.

I suggest that you put C:\j2sdk1.4.2_08\bin at the BEGINNING of the PATH variable instead of the end. I am willing to bet that Windows found a different version of Java than the one you expect. You should also be able to remove "c:\jesdk1.4.2_08\bin;;c:\jesdk1.4.2_08\bin;" from the end of the PATH variable.

HTH

Layne
[ September 20, 2005: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
Hi Layne

Thats what I have done in the modified PATH variable I gave in my post.

Put the DOT and the j2sdk's\bin folder as the first entry...

Regards
Maulin
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Originally posted by Maulin Vasavada:
Hi Layne

Thats what I have done in the modified PATH variable I gave in my post.

Put the DOT and the j2sdk's\bin folder as the first entry...

Regards
Maulin


You don't need to include . in the PATH. In fact you shouldn't, especially on Unix-like systems as this is a security hole.

Also, my comments about changing the contents of the PATH were supposed to be directed to Puthriah. I'm sorry that I didn't make this clear.

Layne
Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
I tried all the suggestions and still faing the same problem.

Appreciate all your help. Any ideas?

Thanks
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Okay, since I'm sure things have changed, we should start over from scratch. First of all, I need some information about how things are set up on your system:

1) Where is the version of Java you plan on using installed?
2) What is the current PATH?
3) What is the current CLASSPATH?

The last one shouldn't be a big issue except that it looks like you may have other software installed that will use it. Once I understand the current settings, then we can work from there.

Layne

p.s. Feel free to send me a private message when you have posted this information here. I don't mind reminders to check the public message boards, but DON'T ask your questions in a private message. Thanks.
Srinivasa Kadiyala
Ranch Hand

Joined: Jun 10, 2004
Posts: 237
Hi Layne Lund
1) j2sdk1.4.2_08

2)path>>>

c:\j2sdk1.4.2_08\bin;C:\oracle\Ora_Client\bin\;C:\Program Files\Oracle\jre\1.1.8\bin\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\Rational\ClearCase\bin;C:\Program Files\Documentum\Shared\;C:\Program Files\Java\j2re1.4.2_08\bin;C:\Program Files\Rational\common;C:\Program Files\Rational\ClearQuest;C:\Program Files\apache-ant-1.6.5\bin;CATALINA_HOME=C:\JBuilderX\thirdparty\jakarta-tomcat-4.1.27-LE-jdk14\bin;

3)classpath>>>

C:\JBuilderX\thirdparty\jakarta-tomcat-4.1.27-LE-jdk14\bin;C:\Program Files\Java\j2re1.4.2_08\lib;C:\j2sdk1.4.2_08\lib;
 
GeeCON Prague 2014
 
subject: Javac error...