Link to home
Start Free TrialLog in
Avatar of emadomar
emadomar

asked on

java compile(class path)

i've compiled the file e.java successfully
but when i try to run it using Java.exe like

C:\jdk1.3.0_02\bin>java -classpath <c:\classes12.zip> e.class
classpath requires class path specification-


i got the message u c above ,
i want to run it from the dos prompt and i don't want to use any IDE
Thank you
Avatar of mohan_sekar
mohan_sekar
Flag of United States of America image

Hi,

   Open AUTOEXEC.BAT file and add the following

 path= c:\jdk1.2\bin;
 set classpath=c:\jdk1.2\lib;.;

   Save the file and restart the machine.

   It solves ur problem

bye
Avatar of Richard_Yu
Richard_Yu

Maybe you not include all classpath for necessary libarys. BTW, when you run a java program you sould not include the .class suffix. For example, you may try:

C\jdk1.3.0_02\bin>java -classpath <c:\classes12.zip;c:\jdk1.3.0_02\lib\tools.
jar;c:\jdk1.3.0_02\lib\jvm.lib> e

maybe you should try to change '<' and '>' with " in classpath arguments
Hi emadomar

Let me answer this type of question again!
I will suggest you a few steps, follow them and you will be successful in the execution of your program.

I observe that you are trying to run the class file from the bin directory.This is ok.but why dont you create your own directory say c:\emadomor.
Edit,save,compile and run your java programs from this folder.
(this is just a bit of advice!!)

secondly you 'should not' include the '.class' extension to run a java program.This results in an error.

next, CORE JAVA CLASSES do not require CLASSPATH TO BE SET.
java.exe is INTELLIGENT enough to locate the required class files (from jar/zip) and RUN them!

next, dont use the angled brackets to include the classpath.
Angled brackets are only a NOTATION used to help the developer how to use a particular program. (you might see this when you just type JAVA at the command prompt)

finally the error that your compiler throws is probably due to the fact that you included the angled brackets and the compiler is not able to recongize them.

to run your program successfully type the following sentence a the command prompt.
Assume the following,

* your class file name is e.class
* your working directory is c:\emadomar
* you have the path set to execute the java,javac files
* you have some classfile named some.class which is    
  residing in c:\emadomar\classes

type the following command now

java -classpath .;c:\emadmor\classes\some.class e

What's this ????:
java -classpath .;c:\emadmor\classes\some.class e

So you said java to use some.class as classpath ??? Hehe. Publish that !
all you have to do is to modify your command line from :
C:\jdk1.3.0_02\bin>java -classpath <c:\classes12.zip> e.class

to :
C:\jdk1.3.0_02\bin>java -classpath <c:\classes12.zip> e

For running a class file you must not specify the extension of that file (e.g. 'java Hello' instead of 'java Hello.class').

Cheers , nice answear you have there :).
to : C:\jdk1.3.0_02\bin>java -classpath c:\classes12.zip e

Hi all


as jori pointed out, i made a mistake.what i really meant was that instead of the class file you use a JAR file.
i mean if there was 'some.jar' then include THAT JAR FILE IN THE CLASSPATH (AND JUST NOT THE DIRECTORY IN WHICH THE JAR FILE IS PRESENT)
something like this

java -classpath .;c:\emadmor\classes\some.jar e

(correct me jori if i am wrong)

it was a mistake.

rameshnut
You are forgiven. :) Hope you weren't angry with me; it was a joke.
Hi all

if authors of java books were like 'ovi' no body would have ever learnt the language :-))
You seem to know things but you dont seem to be able to COMMUNICATE it to others!!.thats a pity!

i would have given answer exactly HALF THE SIZE OF YOURS he he .BUT...alas! emadomar would not have understood it(i assume that this person is a novice).

rameshnut
ASKER CERTIFIED SOLUTION
Avatar of SpideyMod
SpideyMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial