aspose file tools*
The moose likes Beginning Java and the fly likes java on command Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "java on command" Watch "java on command" New topic
Author

java on command

sapna manga
Greenhorn

Joined: Apr 14, 2006
Posts: 5
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
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
You probably need to put the java bin directory in your PATH.


Nathaniel Stodard<br />SCJP, SCJD, SCWCD, SCBCD, SCDJWS, ICAD, ICSD, ICED
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18825
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
sapna manga
Greenhorn

Joined: Apr 14, 2006
Posts: 5
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?
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24184
    
  34

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.


[Jess in Action][AskingGoodQuestions]
sapna manga
Greenhorn

Joined: Apr 14, 2006
Posts: 5
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
jay nair
Greenhorn

Joined: Sep 13, 2005
Posts: 28
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 ....


Preparing for SCJP 5
sapna manga
Greenhorn

Joined: Apr 14, 2006
Posts: 5
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
Vijay Raj
Ranch Hand

Joined: Oct 10, 2005
Posts: 110
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

Joined: Apr 14, 2006
Posts: 5
Thanks
It's working.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
See if this tutorial helps.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Yogendra Joshi
Ranch Hand

Joined: Apr 04, 2006
Posts: 213
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....


Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: java on command