Solved

java compile(class path)

Posted on 2001-06-29
11
603 Views
Last Modified: 2013-11-23
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
0
Comment
Question by:emadomar
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 15

Expert Comment

by:mohan_sekar
ID: 6237267
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
0
 

Expert Comment

by:Richard_Yu
ID: 6237300
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

0
 
LVL 2

Expert Comment

by:jorj
ID: 6237345
maybe you should try to change '<' and '>' with " in classpath arguments
0
 

Expert Comment

by:rameshnut
ID: 6237446
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

0
 
LVL 2

Expert Comment

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

So you said java to use some.class as classpath ??? Hehe. Publish that !
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 9

Expert Comment

by:Ovi
ID: 6237506
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 :).
0
 
LVL 9

Expert Comment

by:Ovi
ID: 6237518
to : C:\jdk1.3.0_02\bin>java -classpath c:\classes12.zip e

0
 

Expert Comment

by:rameshnut
ID: 6237724
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
0
 
LVL 2

Expert Comment

by:jorj
ID: 6237742
You are forgiven. :) Hope you weren't angry with me; it was a joke.
0
 

Expert Comment

by:rameshnut
ID: 6240270
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
0
 

Accepted Solution

by:
SpideyMod earned 0 total points
ID: 8289498
All,
I am unlocking this question in preparation for cleanup.  I will return in 7 days to finalize this question.  Please leave any recommendations for the final state of this question, I will take all recommendations into consideration.  Failing any feedback, I may decide in 7 days to delete or PAQ this question with no refund.  Thanks.

SpideyMod
Community Support Moderator @Experts Exchange
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now