Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Help me please with JDK!

1 view
Skip to first unread message

ramin farhanian

unread,
Jan 17, 2002, 1:16:21 PM1/17/02
to
dear friends
first I downloaded the last version of JDK from java.sun.com but It
didn't work out on my windows 2000 ,so I used that version that was
included in Core Java Book but I still have wierd problems.Help me
please....Thank you
This is what happens:
I install JDK,
C:\jdk\bin>java -version
java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

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

Manfred Leonhardt

unread,
Jan 17, 2002, 1:58:53 PM1/17/02
to
Hi Ramin,

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.

Steve Horsley

unread,
Jan 17, 2002, 2:13:29 PM1/17/02
to
"ramin farhanian" <ramin_f...@hotmail.com> wrote in message
news:d2db27d3.02011...@posting.google.com...
<snip>
I don't know what version of JDK your book came with, so I 'll talk about
Suns JDK 1.3 (which you seem to have).

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.


ramin farhanian

unread,
Jan 18, 2002, 2:01:05 AM1/18/02
to
dear friends
I tried these two solutions,It doesn't work out,please help me!

Kevin Ryan

unread,
Jan 18, 2002, 2:32:35 AM1/18/02
to
Steve Horsley wrote:
>
> "ramin farhanian" <ramin_f...@hotmail.com> wrote in message
> news:d2db27d3.02011...@posting.google.com...
> > ...
> > This is what happens:
> > ...

> > 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

> 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).

Jon Skeet

unread,
Jan 18, 2002, 3:26:51 AM1/18/02
to
Manfred Leonhardt <leo...@cat.com> wrote:
> 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.

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

0 new messages