• Post Reply Bookmark Topic Watch Topic
  • New Topic

Please help with my very first steps installing the JDK  RSS feed

 
Tod Heartsound
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Members,

Yesterday I finally went in and got a Java book: "Core Java" (ed 8) and I am in the first chapters, doing my very first steps.
I installed Java 6 (not 7, because the book is about 6) into: C:\Java. I set up the PATH correctly (even though the instructions
they give in the book are misleading). I tried to run their example program:

Welcome.java
/**
* This program displays a greeting from the authors.
* @version 1.20 2004-02-28
* @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 (String g : greeting)
System.out.println(g);
}
}

I went into the file's directory and typed: javac Welcome.java

and I got:

Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/tools/javac/M
ain
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.Main
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: com.sun.tools.javac.Main. Program will exit.

I tried to search around, including in this forum but I did not manage to find a solution. I think this may be my CLASSPATH variable. I set one up (I didn't have one when I first met this problem) to: c:\java\lib - to no avail...

Any help would be appreciated, I hope to become a contributing member of this community.

Thanks. Tod.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch

Horstmann and Cornell is an excellent book; I have a copy at home. But I am not convinced it is a beginner’s book.
Please tell us how you set your PATH. I can’t see anything wrong with the instructions in the book, but they are a bit laconic. You might find the instructions in our First Program FAQ easier to read. Or the Oracle instructions. Oracle don’t tell you about the PATH on Linux, however.
You didn’t say which OS you are using. It is worth printing your PATH with echo %PATH% (Windosw®) or echo $PATH (Linux) [edit]Correct ech to echo[/edit]. A typical PATH on Windows® reads like
c:\Program Files\Java\jdk1.6.0_32\bin;lotsOfOtherPathsToo. you should put your Java™ entry at the start of the PATH, otherwise you might use a newer version of the javac tool than the java tool, which causes problems.

Since you are new, I have added code tags to your post, and you can see how much better it looks. I also managed to copy your post rather than editing it, by mistake, so had to delete my post and start again
 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Tod

It seems the path you have set is not correct. Set the path to the folder where the jdk is located.
 
Tod Heartsound
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the replies. Here are my replies:

1. About the book: it seems to hit me where I like, not too "for dummies" with their stupid jokes and kindergarten-level analogies. I am a programmer in Prolog (too bad it's not sought-after in the market) so the book is about my level.

2. The mistake in the book: They say that to verify that we installed the JDK correctly, we should run: java -version - but this is the JRE. The first time I ran it, it was OK even though I didn't set the PATH correctly and later, when the
jar xvf ..\src.zip didn't work, I was very frustrated. The second error they did was that when telling us how to set the path, they didn't tell us to restart the CMD, which led to more frustration and googling.

3. I use Win 7. I installed my java into: c:\java and I set the PATH to: c:\java\bin - I think this is correct because before I did that, the jar program did not work but it did work afterwards.

4. echo path: c:\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\

5. echo classpath: c:\java\lib (I created this variable myself, in lowercase)

 
Sumit Patil
Ranch Hand
Posts: 296
Eclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you able to run the program now?
I am not sure if the path you have set is correct (c:java\lib).

The path needs to point to the bin directory which is inside the jdk folder (something like c:\java\jdk..\bin)

Here is a example.

Hope this helps.
 
Tod Heartsound
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not able to run the program. I did not do anything after posting on this forum.
I don't have a folder "java" for all the JDK's. My "JDK" folder is the "java" folder. The PATH currently points to the bin directory,
where the jar, javac, java executables are. I don't believe it is set incorrectly.

What I do think is wrong is that the tools.jar file is missing. Could you check if you have such a file in your jdk/lib folder?

Reading around the internet, I see this is a classpath problem but all the instructions there are when this problem is met at a much more complicated project and they are too high level for me.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have programmed in other languages previously, then Horstmann and Cornell is a very good choice.

Did you notice the spelling errors in my previous post: I wrote ech when it should have read echo?
A PATH entry ending in lib is incorrect; it should end in bin. Sumit Patel’s link shows examples, but it may read jdk1.7.0_04 or similar rather than plain simple jdk1.7.0. Actually, it is better to verify an installation with javac ‑version because there is often a java tool in a JRE elsewhere in the path. If you find the javac tool, you can be confident that you have found a JDK.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you set that classpath variable yourself? As it says in H&C, it usually does more harm than good to set a system classpath. If you set it yourself, you should delete it altogether. If not, you should add .; dot‑semicolon to its beginning. And sorry that I mistook your classpath for a path earlier.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have a jdk folder inside your c:\Java folder then your path entry ought to have the name of that JDK folder in.
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Contents of my Program Files\Java\jdk1.7.0_04 folder: jdk1.7.0_04]$ ls
bin db jre LICENSE release THIRDPARTYLICENSEREADME.txt
COPYRIGHT include lib README.html src.zip
Contents of bin:
appletviewer.exe javaw.exe jstack.exe policytool.exe
apt.exe javaws.exe jstatd.exe rmic.exe
extcheck.exe jcmd.exe jstat.exe rmid.exe
idlj.exe jconsole.exe jvisualvm.exe rmiregistry.exe
jar.exe jdb.exe keytool.exe schemagen.exe
jarsigner.exe jhat.exe kinit.exe serialver.exe
javac.exe jinfo.exe klist.exe servertool.exe
javadoc.exe jli.dll ktab.exe tnameserv.exe
java.exe jmap.exe msvcr100.dll unpack200.exe
javah.exe jps.exe native2ascii.exe wsgen.exe
javap.exe jrunscript.exe orbd.exe wsimport.exe
java-rmi.exe jsadebugd.exe pack200.exe xjc.exe
contents of db:
3RDPARTY bin lib LICENSE NOTICE README-JDK.html RELEASE-NOTES.html
contents of jre folder:
bin lib README.txt Welcome.html
COPYRIGHT LICENSE THIRDPARTYLICENSEREADME.txt

Things like bin db include jre and lib mean folders with those names. I think if you don’t have tools.jar and rt.jar in the same locations as me, you might do well to repeat the installation.
 
Tod Heartsound
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Campbell Ritchie,

Thanks for picking up this thread, I know it must be so boring compared to real programming issues.

1. I did not understand, in which folder is your tools.jar file?
2. Running javac - version gives the same error but is this error 100% certain due to the path variable? I read this is something about classes being available at compilation time but not at some other time?

I am going to uninstall the java 6 and install the java 7 while I wait for your response.
 
Tod Heartsound
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK, I managed to make it work. It was just that the java 6 installation package is faulty (or doesn't work well on my computer). I reinstalled java 6, the same thing. I redownloaded - the same. I downloaded the java 7u4 and it works like a charm.

Thanks to all who helped. See you soon again! ;)
 
Campbell Ritchie
Marshal
Posts: 56600
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done getting it to work

I would appear to have tools.jar in the lib folder, which I forgot to enumerate. Sorry about that. I cannot understand why you were having difficulty with Java6. I presume you didn’t get confused between the 32‑bit and 64‑bit versions.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!