I set the path :
C:\jdk\bin ; %SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
I can compile it easily and the compiler generates a class file but I
can not
run it,while I run it ,I get this message:
Exception in thread "main" java.lang.NoClassDefFoundError: c:\Welcome
Please don't tell me that you have a syntax Error.I just run Samples
of Core Java book .
In the book ,It's recommended that I run this command
jar xvf src.jar
while I do that normally,I get this message :
C:\jdk\bin>jar xvf src.jar
java.io.FileNotFoundException: src.jar (The system cannot find the
file specified)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:64)
at sun.tools.jar.Main.run(Main.java:186)
at sun.tools.jar.Main.main(Main.java:904)
and this is the source code that I compile (Of course there's no bug):
/**
@version 1.11 2000-04-22
@author Cay Horstmann
*/
public class Welcome
{
public static void main(String[] args)
{
String[] greeting = new String[3];
greeting[0] = "Welcome to Core Java";
greeting[1] = "by Cay Horstmann";
greeting[2] = "and Gary Cornell";
for (int i = 0; i < greeting.length; i++)
System.out.println(greeting[i]);
}
}
In Core Java It's recommended that I unzip the doc file using jar
command in the end.
As there's to be some HTML document inside the doc folder,Is it quite
necessary in JDK installation?
========================================================================
Please tell me what to do...Thank you very much indeed!
Regards
Ramin Farhanian
Try setting your classpath variable:
set CLASSPATH=.
This will allow you to run the file if you are in the directory where the
class file exists.
Regards,
Manfred.
Ignoring the jar command, you should be able to run the Welcome class file
(assuming it compiled, and it sounds like it did) by changing directories so
that your default directory is the one where the class file is, and typing
"java Welcome". Do NOT put any path on the front of the class name, just
make sure you're in the same directory first.
Example: if Welcome.class is ins C:\ (full filename is then
C:\Welcome.class)
then the prompt and command is:
C:\> java Welcome
The jar command you posted is to extract all the source code for the java
API from its jar file.
I don't see why you might want to do this, but if you really do, I find that
my src.jar is NOT in the bin directory.
In my PC, it's in C:\jdk1.3\src.jar so you need to do
C:\jdk1.3> jar xvf src.jar
As a general rule, I would suggest making a special directory for your java
work (maybe C:\java), and doing everything in there.
C:\java> notepad Welcome.java
C:\java> javac Welcome.java
C:\java> java Welcome
Also, have a look at a lovely IDE called BlueJ (www.bluej.org). It's
intended for beginners. It's a small free download, easy to install, has all
the things you REALLY need (nice editor, a compile button, debuger) but it's
still extremely easy and uncomplicated to use.
Steve.
> Ignoring the jar command, you should be able to run the Welcome class file
> (assuming it compiled, and it sounds like it did) by changing directories so
> that your default directory is the one where the class file is, and typing
> "java Welcome". Do NOT put any path on the front of the class name, just
> make sure you're in the same directory first.
> Example: if Welcome.class is ins C:\ (full filename is then
> C:\Welcome.class)
> then the prompt and command is:
> C:\> java Welcome
Ramin,
Steve Horsley's suggestion SHOULD solve (have solved) your problem.
Please consider re-checking your steps, since the symptom you describe
is precisely what would occur if you type (incorrectly)
java C:\Welcome
instead of the correct
java Welcome
ASSUMING you are typing the latter command from the directory where the
.class file resides. (If not, adding a path to qualify the .class
file's location will NOT work as you might expect it to.)
Until you get more comfortable with the mechanics of the various tools,
it's best to plan to compile (javac) and run (java) from "." -- meaning,
from the directory where the .java and the resulting .class file(s)
reside.
Even when you start using java package(name)s, you'll often want to be
compiling and running relative to ".".
You may want to look at the online tools docs at java.sun.com, to
supplement the directions in Horstmann's book. The tools docs can be
found at:
http://java.sun.com/j2se/1.3/docs/tooldocs/tools.html
Note the section on "how classes are found". When you run into
problems, consider reviewing the syntax/mechanics for a given command.
This often helps you identify minor errors quickly.
Best Regards,
KR
P.S. With Java 2 (i.e., versions 1.2., 1.3, 1.4 and beyond), you often
don't need/want an explicit CLASSPATH. Under win32, a good starting
point is:
C:> set CLASSPATH=
(i.e., set it to NOTHING) This will pick up any classes in "." (and
relative to ".", for packagename-qualified classnames), plus all
standard java classes (the stuff in rt.jar), plus any installed
extensions (anything, such as the contents of .jar files containing
classes, in the jre/ext subdir of your development-kit/runtime tree).
That won't help - not having any classpath set at all is (IMO)
preferrable to having one set to "." as "." is the default, and you
don't need to worry about getting it wrong if you're not setting it at
all.
The problem was almost certainly running java c:\Welcome rather than
java Welcome.
--
Jon Skeet - <sk...@pobox.com>
http://www.pobox.com/~skeet/
If replying to the group, please do not mail me too