Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'javac' is not recognized 1

Status
Not open for further replies.

xbl12

Programmer
Dec 12, 2006
66
Hello;
I just downloaded a jdk-6-windows-i586.exe, and i set a PATH for it is C:\Program Files\Java\jdk1.6.0_<version>\bin, But when i run my application, it tell me that the 'javac' is not recognized. Could anyone tell me why, thanks.

I just download the jdk-1_5_0_11-windows-i586-p.exe last night, and it was not problem for compile and run my application.

Because i want to be familiar with JDK, so i downloaded another JDK6 and delete the old one, and play around with them.

The following are the job i have done:

compile my application

E:\Java>echo %PATH%
C:\j2sdk1.4.2_10\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Commo
n Files\Adobe\AGL;C:\Program Files\Microsoft SQL Server\80\Tools\BINN


E:\Java>javac HelloWorldSwing.java
'javac' is not recognized as an internal or external command,
operable program or batch file.



/////////////////////////////////////////////////////////

check my jdk directory

C:\Program Files\Java>dir
Volume in drive C has no label.
Volume Serial Number is 3023-229B

Directory of C:\Program Files\Java

03/02/2007 04:54 PM <DIR> .
03/02/2007 04:54 PM <DIR> ..
01/02/2007 10:54 PM <DIR> j2re1.4.2_13
03/02/2007 04:54 PM <DIR> jdk1.6.0
01/02/2007 10:02 PM <DIR> jre1.5.0_06
03/02/2007 04:55 PM <DIR> jre1.6.0
0 File(s) 0 bytes
6 Dir(s) 5,771,837,440 bytes free

C:\Program Files\Java>cd jdk1.6.0

C:\Program Files\Java\jdk1.6.0>dir
Volume in drive C has no label.
Volume Serial Number is 3023-229B

Directory of C:\Program Files\Java\jdk1.6.0

03/02/2007 04:54 PM <DIR> .
03/02/2007 04:54 PM <DIR> ..
03/02/2007 04:53 PM <DIR> bin
29/11/2006 03:47 AM 2,539 COPYRIGHT
03/02/2007 04:53 PM <DIR> db
03/02/2007 04:54 PM <DIR> demo
03/02/2007 04:53 PM <DIR> include
03/02/2007 04:53 PM <DIR> jre
03/02/2007 04:53 PM <DIR> lib
03/02/2007 04:53 PM 13,471 LICENSE
03/02/2007 04:53 PM 19,780 LICENSE.rtf
03/02/2007 04:53 PM 26,022 README.html
03/02/2007 04:53 PM 20,640 README_ja.html
03/02/2007 04:53 PM 15,523 README_zh_CN.html
03/02/2007 04:54 PM <DIR> sample
29/11/2006 03:48 AM 19,248,578 src.zip
03/02/2007 04:53 PM 177,928 THIRDPARTYLICENSEREADME.txt
8 File(s) 19,524,481 bytes
9 Dir(s) 5,771,837,440 bytes free

C:\Program Files\Java\jdk1.6.0>cd bin

C:\Program Files\Java\jdk1.6.0\bin>dir
Volume in drive C has no label.
Volume Serial Number is 3023-229B

Directory of C:\Program Files\Java\jdk1.6.0\bin

03/02/2007 04:53 PM <DIR> .
03/02/2007 04:53 PM <DIR> ..
03/02/2007 04:53 PM 25,600 appletviewer.exe
03/02/2007 04:53 PM 25,600 apt.exe
03/02/2007 04:53 PM 29,184 beanreg.dll
03/02/2007 04:53 PM 25,600 extcheck.exe
03/02/2007 04:53 PM 45,056 HtmlConverter.exe
03/02/2007 04:53 PM 25,600 idlj.exe
03/02/2007 04:53 PM 25,600 jar.exe
03/02/2007 04:53 PM 25,600 jarsigner.exe
03/02/2007 04:53 PM 25,088 java-rmi.exe
03/02/2007 04:53 PM 135,168 java.exe
03/02/2007 04:53 PM 25,600 javac.exe
03/02/2007 04:53 PM 25,600 javadoc.exe
03/02/2007 04:53 PM 25,600 javah.exe
03/02/2007 04:53 PM 25,600 javap.exe
03/02/2007 04:53 PM 135,168 javaw.exe
03/02/2007 04:53 PM 139,264 javaws.exe
03/02/2007 04:53 PM 26,112 jconsole.exe
03/02/2007 04:53 PM 25,600 jdb.exe
03/02/2007 04:53 PM 25,600 jhat.exe
03/02/2007 04:53 PM 25,600 jinfo.exe
03/02/2007 04:53 PM 77,824 jli.dll
03/02/2007 04:53 PM 25,600 jmap.exe
03/02/2007 04:53 PM 25,600 jps.exe
03/02/2007 04:53 PM 25,600 jrunscript.exe
03/02/2007 04:53 PM 25,600 jstack.exe
03/02/2007 04:53 PM 25,600 jstat.exe
03/02/2007 04:53 PM 25,600 jstatd.exe
03/02/2007 04:53 PM 25,600 keytool.exe
03/02/2007 04:53 PM 25,600 kinit.exe
03/02/2007 04:53 PM 25,600 klist.exe
03/02/2007 04:53 PM 25,600 ktab.exe
29/11/2006 03:41 AM 348,160 msvcr71.dll
03/02/2007 04:53 PM 25,600 native2ascii.exe
03/02/2007 04:53 PM 25,600 orbd.exe
03/02/2007 04:53 PM 25,600 pack200.exe
03/02/2007 04:53 PM 73,728 packager.exe
03/02/2007 04:53 PM 25,600 policytool.exe
03/02/2007 04:53 PM 25,600 rmic.exe
03/02/2007 04:53 PM 25,600 rmid.exe
03/02/2007 04:53 PM 25,600 rmiregistry.exe
03/02/2007 04:53 PM 25,600 schemagen.exe
03/02/2007 04:53 PM 25,600 serialver.exe
03/02/2007 04:53 PM 25,600 servertool.exe
03/02/2007 04:53 PM 26,112 tnameserv.exe
03/02/2007 04:53 PM 122,880 unpack200.exe
03/02/2007 04:53 PM 25,600 wsgen.exe
03/02/2007 04:53 PM 25,600 wsimport.exe
03/02/2007 04:53 PM 25,600 xjc.exe
48 File(s) 2,105,344 bytes
2 Dir(s) 5,771,837,440 bytes free
 
But it still not work.

In the user variable section, i added details as following:

variable name: Path
Value: C:\Program Files\Java\jdk1.6.0\bin

And i could not find the path from Dos.

C:\Documents and Settings\Kam Liu>echo %path%
The system cannot find the file specified.

E:\Java>javac HelloWorldSwing.java
'javac' is not recognized as an internal or external command,
operable program or batch file.
 
I could compile my application now, but now i meet another problem as following: am i still short something ?


E:\Java>java HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing

C:\Documents and Settings\kam>path
PATH=C:\Program Files\Java\jdk1.6.0\bin;c:\Program Files\Java\j2re1.4.2\javaws



Code:
import javax.swing.*;        

public class HelloWorldSwing {
  
    private static void createAndShowGUI() {
        //Make sure we have nice window decorations.
        JFrame.setDefaultLookAndFeelDecorated(true);

        //Create and set up the window.
        JFrame frame = new JFrame("HelloWorldSwing");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Add the ubiquitous "Hello World" label.
        JLabel label = new JLabel("Hello World");
        frame.getContentPane().add(label);

        //Display the window.
        frame.pack();
        frame.setVisible(true);
    }

    public static void main(String[] args) {
        //Schedule a job for the event-dispatching thread:
        //creating and showing this application's GUI.
        javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
 
You should be able to compile using (at the prompt):
C:\Program Files\Java\jdk1.6.0\bin\javac MyClass.java

And to set the path:
"Choose Start, Settings, Control Panel, and double-click System. On Microsoft Windows NT, select the Environment tab; on Microsoft Windows 2000 select the Advanced tab and then Environment Variables. Look for "Path" in the User Variables and System Variables." <-- If you do this, this will only work for new console/DOS windows opened, for the windows already opened at the commandline:
Code:
set path=C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\Microsoft SQL Server\80\Tools\BINN
(no returns)

[plug=shameless]
[/plug]
 
It still could not run my application, compile is fine, it seems miss something???

C:\Documents and Settings\kam Liu>path
PATH=C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\QuickTime\QTSystem\;C:\
Program Files\Common Files\Adobe\AGL;C:\Program Files\Microsoft SQL Server\80\To
ols\BINN;C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\QuickTime\QTSystem\
;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\Microsoft SQL Server\8
0\Tools\BINN


///////////////////////////////////


E:\Java>javac HelloWorldSwing.java

E:\Java>java HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing
 
Alter your CLASSPATH environment variable to include the location your HelloWorldSwing.class directory.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Sorry, I was writting my post when you posted...

sedj, ./ (.\ in windows) is always in Classpath, even if not listed.

looking at the directory listing, java isn't in the same directory as javac, so java's location (jre's) needs to added to the path as well.

add to your path (at the beginning), without removing anything else:
C:\Program Files\Java\jre1.6.0;
and\or
C:\Program Files\Java\jre1.6.0\bin;


[plug=shameless]
[/plug]
 
But it still does not work too,and i removed all the jdks from controll pannel and regedit. All gone, and downloaded a new jdk6, but it still have the some problem, but the command of the java -cp . HelloWorld works fine.


///////////////////////////////////////////////////////


Can i say that something wrong with the JDK6 they offer,
i get it from
and my states as followings:

C:\Documents and Settings\XiaoBin Liu>path
PATH=C:\WINDOWS\System32;C:\Program Files\Java\jre1.6.0;C:\Program Files\QuickTi
me\QTSystem\;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\Microsoft
SQL Server\80\Tools\BINN;C:\Program Files\Java\jdk1.6.0\bin;sedj, ./ (.\ in wind
ows)


E:\Java>javac HelloWorldSwing.java

E:\Java>java HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing

E:\Java>java -cp . HelloWorldSwing

And I also tried several method from the following:
1)
E:\Java>set CLASSPATH=C:\Program Files\Java\jdk1.6.0\bin

E:\Java>javac HelloWorldSwing.java

E:\Java>java HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing

2) move my file to C:\Program Files\Java\jdk1.6.0\bin to compile and run it, it still not work.

3) moved my file to C:\Program Files\Java to comiple and run it, it also not work.

////////////////////////////////////////////////////////////////////////////////////////////////////////////
and my jdk details as following:

C:\Program Files\Java>dir
Volume in drive C has no label.
Volume Serial Number is 3023-229B

Directory of C:\Program Files\Java

04/02/2007 02:48 PM <DIR> .
04/02/2007 02:48 PM <DIR> ..
04/02/2007 02:48 PM <DIR> jdk1.6.0
04/02/2007 02:48 PM <DIR> jre1.6.0
0 File(s) 0 bytes
4 Dir(s) 5,781,045,248 bytes free

C:\Program Files\Java>cd jdk1.6.0

C:\Program Files\Java\jdk1.6.0>cd bin

C:\Program Files\Java\jdk1.6.0\bin>dir
Volume in drive C has no label.
Volume Serial Number is 3023-229B

Directory of C:\Program Files\Java\jdk1.6.0\bin

04/02/2007 02:46 PM <DIR> .
04/02/2007 02:46 PM <DIR> ..
04/02/2007 02:46 PM 25,600 appletviewer.exe
04/02/2007 02:46 PM 25,600 apt.exe
04/02/2007 02:46 PM 29,184 beanreg.dll
04/02/2007 02:46 PM 25,600 extcheck.exe
04/02/2007 02:46 PM 45,056 HtmlConverter.exe
04/02/2007 02:46 PM 25,600 idlj.exe
04/02/2007 02:46 PM 25,600 jar.exe
04/02/2007 02:46 PM 25,600 jarsigner.exe
04/02/2007 02:46 PM 25,088 java-rmi.exe
04/02/2007 02:46 PM 135,168 java.exe
04/02/2007 02:46 PM 25,600 javac.exe
04/02/2007 02:46 PM 25,600 javadoc.exe
04/02/2007 02:46 PM 25,600 javah.exe
04/02/2007 02:46 PM 25,600 javap.exe
04/02/2007 02:46 PM 135,168 javaw.exe
04/02/2007 02:46 PM 139,264 javaws.exe
04/02/2007 02:46 PM 26,112 jconsole.exe
04/02/2007 02:46 PM 25,600 jdb.exe
04/02/2007 02:46 PM 25,600 jhat.exe
04/02/2007 02:46 PM 25,600 jinfo.exe
04/02/2007 02:46 PM 77,824 jli.dll
04/02/2007 02:46 PM 25,600 jmap.exe
04/02/2007 02:46 PM 25,600 jps.exe
04/02/2007 02:46 PM 25,600 jrunscript.exe
04/02/2007 02:46 PM 25,600 jstack.exe
04/02/2007 02:46 PM 25,600 jstat.exe
04/02/2007 02:46 PM 25,600 jstatd.exe
04/02/2007 02:46 PM 25,600 keytool.exe
04/02/2007 02:46 PM 25,600 kinit.exe
04/02/2007 02:46 PM 25,600 klist.exe
04/02/2007 02:46 PM 25,600 ktab.exe
29/11/2006 03:41 AM 348,160 msvcr71.dll
04/02/2007 02:46 PM 25,600 native2ascii.exe
04/02/2007 02:46 PM 25,600 orbd.exe
04/02/2007 02:46 PM 25,600 pack200.exe
04/02/2007 02:46 PM 73,728 packager.exe
04/02/2007 02:46 PM 25,600 policytool.exe
04/02/2007 02:46 PM 25,600 rmic.exe
04/02/2007 02:46 PM 25,600 rmid.exe
04/02/2007 02:46 PM 25,600 rmiregistry.exe
04/02/2007 02:46 PM 25,600 schemagen.exe
04/02/2007 02:46 PM 25,600 serialver.exe
04/02/2007 02:46 PM 25,600 servertool.exe
04/02/2007 02:46 PM 26,112 tnameserv.exe
04/02/2007 02:46 PM 122,880 unpack200.exe
04/02/2007 02:46 PM 25,600 wsgen.exe
04/02/2007 02:46 PM 25,600 wsimport.exe
04/02/2007 02:46 PM 25,600 xjc.exe
48 File(s) 2,105,344 bytes
2 Dir(s) 5,781,045,248 bytes free

Edit/Delete Message
 
Code:
E:\Java>javac HelloWorldSwing.java

E:\Java>java HelloWorldSwing
Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorldSwing
This means it's finding the JDK (Java Development Kit), but not JRE (Java Runtime Enviroment -- aka JVM or Java virtual machine).

You need both installed and both in your path.
re-download and install the jre1.6.0, and set your path to:

Code:
C:\Program Files\Java\jre1.6.0;C:\Program Files\Java\jdk1.6.0\bin;C:\Program Files\QuickTime\QTSystem\;C:\Program Files\Common Files\Adobe\AGL;C:\Program Files\Microsoft SQL Server\80\Tools\BINN
(no returns)

If you still have trouble just alias the java, javadoc and javac executables to their names.

[plug=shameless]
[/plug]
 
jsreich,

The error means that the poster's CLASSPATH is not set to include where the poster's .class file is - not that it cannot find the JRE.

NoClassDefFoundError means "I cannot find the class you are trying to execute" - not "I cannot find a JRE".

If it could not find the JRE, then the error would be "Cannot find programme or executable named 'java'".

As I said before, the poster needs to add the directory in which the HelloWorldSwing.class file lives. If that directory has spaces in, then the directory needs to be encased with double quotes.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
he error means that the poster's CLASSPATH is not set to include where the poster's .class file is - not that it cannot find the JRE.

NoClassDefFoundError means "I cannot find the class you are trying to execute" - not "I cannot find a JRE
I stand corrected, you are right... This is a classpath or rootclasspath problem. I don't know why when I read it, my brain read "Command not found" ... *feels stupid a second or nine.*

Working in Linux with both the Sun's JVM and JDK, and GNU's unstable and in development java compiler when I don't have my path set to the right JDK/JRE I get that exeception or complaints about trying to use swing...

As I said before, the poster needs to add the directory in which the HelloWorldSwing.class file lives. If that directory has spaces in, then the directory needs to be encased with double quotes.
I don't think this is case... She's running it from the directory she is currently in, and the documentation from sun says:

If -classpath and -cp are not used and CLASSPATH is not set, the user class path consists of the current directory (.).

and the poster also said they tried
E:\Java>java -cp . HelloWorldSwing
which makes me wonder if the bootclasspath points to the wrong rt.jar file.

To check if this is the case locate the file rt.jar in the jre1.6.0 directory and try using the switch
Code:
-Xbootclasspath:bootclasspath
                           Specify  a  colon-separated list of directories, JAR archives, and ZIP archives to search for
                           boot class files.  These are used in place of the boot class files included  in  the  Java  2
                           SDK.  Note: Applications that use this option for the purpose of overriding a class in rt.jar
                           should not be deployed as doing so would contravene the Java  2  Runtime  Environment  binary
                           code license.
to point to it.

[plug=shameless]
[/plug]
 
Hi Sedj;
I have already tried to move the HelloWorldString.java to C:\Program Files\Java\jdk1.6.0\bin and C:\Program Files\Java to compile and run it respectly, it still not work.

But when i run with the command of java -cp . HelloWorld , it works fine, not problem with this.
 
Hi jstreich;
>which makes me wonder if the bootclasspath points to the wrong rt.jar >file.

>To check if this is the case locate the file rt.jar in the jre1.6.0 directory >and try using the switch to point to it.

i can see the rt.jar file in the directory of C:\Program Files\Java\jre1.6.0\lib.

but when i switch to it, it give me the following massage:

C:\Program Files\Java\jre1.6.0\lib>switch rt.jar
'switch' is not recognized as an internal or external command,
operable program or batch file.
 
But when i run with the command of java -cp . HelloWorld , it works fine, not problem with this.
That isn't what you said earlier... *sigh*

What I thought was happening, wasn't, because your posts are a little hard to follow. I thought you said that running with java -cp . HelloWorld wasn't working. So, you have to run with -cp . unless you permently alter your classpath or you alias java to be java -cp . ... this would only be for convience sake. That said, looks like you have everything working now.

It's odd that the two version of Java's JVM (Linux vrs Windows) are different in the way they handle classpath, Linux adds the current working directory by default.

Star for Sedj, because he was right and I was... well, you know, not so right.... :p

[plug=shameless]
[/plug]
 

I am sorry that my posts make you are hard to follow.

And thanks for your patient, you were very helpfull. Something, right or wrong is not so important, nobody can be right all the time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top