• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

java on command

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
I installed jdk1.5.0_06 and as per sun installation guide i added java\jdk1.5.0_06\bin etc. to class path.
I tried the following commands at command promt c:\>
java - verion and it's worked.
when i tried c:\> javac
it is giving 'javac' is not recognized as an internal or external command,operable program or batch file.
if i tried it at promt C:\Program Files\Java\jdk1.5.0_06\bin> javac it is giving all it's options.
if i try C:\Program Files\Java\jdk1.5.0_06\bin> javac hellowworld.java
It is giving
"error: error reading C:\Program Files\Java\jdk1.5.0_06\bin\javac.exe; error in opening zip file"

Why i can't compile a program? I added every thing to classpath.

Please help me . I'm desparate to get it done.

thanks,
Sapna
 
Ranch Hand
Posts: 1258
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You probably need to put the java bin directory in your PATH.
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I installed jdk1.5.0_06 and as per sun installation guide i added java\jdk1.5.0_06\bin etc. to class path.



Did you add the bin directory to the PATH? or CLASSPATH? It is supposed to be the PATH environment variable.

Henry
 
sapna manga
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes i did. This is my classpath

C:\Program Files\Java\jdk1.5.0_06\bin;C:\Program Files\Java\jdk1.5.0_06\bin\javac.exe;C:\Program Files\Java\jdk1.5.0_06\bin\java.exe;C:\Program Files\Java\jdk1.5.0_06\lib;C:\Program Files\Java\jdk1.5.0_06\lib\tools.jar;C:\Program Files\Java\jdk1.5.0_06\bin\jar.exe;C:\Program Files\Java\jdk1.5.0_06\bin\javah.exe

is there anything wrong in this?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are two different environment variables we are talking about.

One is PATH. Windows uses it to find programs to run. The entries are directories in which *.EXE files can be found.

The other is CLASSPATH. Java uses it to find *.CLASS files to load. The entries are *.JAR files containing classes, or directories containing classes.

For someone just starting out in Java, PATH should include an entry for "C:\Program Files\Java\jdk1.5.0_06\bin\". CLASSPATH should not be defined. If you have a definition for CLASSPATH, delete it.

Note that the example you just showed above, with all the *.EXE files listed, is completely incorrect no matter what variable you're talkiing about. Neither PATH nor CLASSPATH would ever include *.EXE files.
 
sapna manga
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks.
i removed .exe files from my class path . now javac is working . i am able to compile .java and no errors.
but when i say c:\> java helloworld it is giving error"Exception in thread "main" java.lang.NoClassDefFoundError: helloworld/class"

How can i get rid of it?

--sapna
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sapna manga:
thanks.
i removed .exe files from my class path . now javac is working . i am able to compile .java and no errors.
but when i say c:\> java helloworld it is giving error"Exception in thread "main" java.lang.NoClassDefFoundError: helloworld/class"

How can i get rid of it?

--sapna




if u are in C:\ then you have to make sure the helloworld.java file is there in c:> itslef else it will give this error ... u hv to be in folder in which u have the .java file in order to compile and run it ....
 
sapna manga
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have both .java and .class files are in c drive and i'm running the java class file from C only.
I'm doing
c:\> java helloworld
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Make sure the crrent director is in the CLASSPATH. you can do this by adding '.' in the CLASSPATH. For example, CLASSPATH = .;C:\java;C:\ibm\

The dot in the beginning tells the java rntime to check for classes in teh current directory also.

regards,
vijay.
 
sapna manga
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks
It's working.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
See if this tutorial helps.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey , Also there is an switch which can be helpful in case the user is not in the directory where the java , class files are located and still they want to compile and run them.

Here's how , Like sapna said , She had her her Java and class files in C:\ i.e root , What she might have done is , She might have given a command like this

c:>javac - d . helloworld.java

And it compiles and run's just fine..

Have a great day !

Yogendra Joshi.

Yesterday is a history , Today is a Gift , Tomorrow is a Mystery....
 
reply
    Bookmark Topic Watch Topic
  • New Topic