Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Command line, Env Variables

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to return to running Java commands from the command line, but I'm
getting either "NoClassDefFoundError" or "Cannot read xxxxx.java file" messages when I do so. I've tried various additions to the CLASSPATH or PATH environment variables, but I still don't have it right, as I used to.

The files I want to compile/run are in
C:\Documents and Settings\jsandma\workspace\SCJP\scjp

The SDK is in C:\Program Files\Java\jre1.5.0_12\bin

What do I need to do to my CLASSPATH or PATH environment variables to fix this ?
I'd like to make it so that I can run Java commands from anywhere in the directory.

Current Java version:

C:\Program Files\Java\jdk1.5.0_12\bin>java -version
java version "1.5.0_12"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_12-b04)
Java HotSpot(TM) Client VM (build 1.5.0_12-b04, mixed mode, sharing)

Here's the Env Variables' current contents:

CLASSPATH

.;
c:\sql\ASEP\3pclass.zip;
c:\sql\ASEP\monclass.zip;
C:\Eclipse\workspace\LossPrevention\src\com\lifeway\aspectLP;
C:\Java\SCP\Java Packages;
C:\j2sdk1.4.2_04\bin;
C:\Program Files\Java\jre1.5.0_06\lib\ext\QTJava.zip;
C:\Documents and Settings\jsandma\workspace\SCJP\scjp;
C:\Program Files\Java\jre1.5.0_12\bin;
C:\Documents and Settings\jsandma\SCJP\build\classes



PATH

c:\sql\ASEP;
c:\sql\OCS-12_0\dll;
c:\sql\OCS-12_0\bin;
C:\WINNT\SYSTEM32;
C:\WINNT;
C:\WINNT\SYSTEM32\WBEM;
C:;
C:\SQL\ADAPTIVE SERVER IQ 12\WIN;
C:\SQL\ADAPTIVE SERVER IQ 12\WIN32;
C:\SQL\BIN;C:\SQL\DLL;
C:\DMI\WIN32\BIN;
C:\sun\sdk;
C:\sun\sdk\lib\ant\bin;
C:\Projects\Cosmos\src;
C:\Program Files\Microsoft SQL Server\80\Tools\BINN;
C:\PROGRA~1\IBM\CLIENT~1;
C:\PROGRA~1\IBM\CLIENT~1\Shared;
C:\PROGRA~1\IBM\CLIENT~1\Emulator;
c:\sql\SQLRemote\dll;
C:\Program Files\QuickTime\QTSystem\;
C:\Program Files\Java\jdk1.5.0_12\bin


Thanks,
Jim S.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jim Sandman:
The SDK is in C:\Program Files\Java\jre1.5.0_12\bin


No, it's not; that's the JRE (Java Runtime Environment), which is not the SDK / JDK.

What do I need to do to my CLASSPATH or PATH environment variables to fix this ?


You'll have to add the directory C:\Documents and Settings\jsandma\workspace\SCJP\scjp to your classpath. Note that that directory name has spaces in it, so you'll have to put it in quotes if you set it on the command line:

set CLASSPATH="C:\Documents and Settings\jsandma\workspace\SCJP\scjp"

Note that if you're setting it in the Windows environment variables settings (Start / right-click My Computer / Properties / Advanced / Environment Variables) you need to close and re-open the command prompt window after changing the environment variables there - the command prompt window does not immediately pick up the changes.
[ September 27, 2007: Message edited by: Jesper Young ]
 
Jim Sandman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jesper Young:

You'll have to add the directory C:\Documents and Settings\jsandma\workspace\SCJP\scjp to your classpath. ]



That directory is already set in CLASSPATH. (see third from bottom in the CLASSPATH list in my first post).
Not sure what else to check.

Yes, "JRE" is what I intended.
Thanks,
Jim
[ September 27, 2007: Message edited by: Jim Sandman ]
 
Jim Sandman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just added C:\Program Files\Java\jdk1.5.0_12\bin
to CLASSPATH (it was already in PATH) and was able to compile a file while in the C:\Documents and Settings\jsandma\workspace\SCJP\scjp directory.

But when running the file (java ToStringDemo) I got:

C:\Documents and Settings\jsandma\workspace\SCJP\scjp>java ToStringDemo
Exception in thread "main" java.lang.NoClassDefFoundError: ToStringDemo (wrong name: scjp/ToStringDemo)

So, I still don't have something right.
[ September 27, 2007: Message edited by: Jim Sandman ]
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Jim Sandman:
I've just added C:\Program Files\Java\jdk1.5.0_12\bin
to CLASSPATH (it was already in PATH) and was able to compile a file while in the C:\Documents and Settings\jsandma\workspace\SCJP\scjp directory.


The CLASSPATH is what Java uses to find class files. Adding the bin directory of the JDK to the CLASSPATH has no effect.

But when running the file (java ToStringDemo) I got:

C:\Documents and Settings\jsandma\workspace\SCJP\scjp>java ToStringDemo
Exception in thread "main" java.lang.NoClassDefFoundError: ToStringDemo (wrong name: scjp/ToStringDemo)


Do you have a 'package' statement in your source file?

package scjp;

If that's the case, then you should add the directory "C:\Documents and Settings\jsandma\workspace\SCJP" (note, leave off the last "\scjp") to your CLASSPATH, and you should compile it and run it like this:

C:\Documents and Settings\jsandma\workspace\SCJP> javac scjp\ToStringDemo.java

C:\Documents and Settings\jsandma\workspace\SCJP> java scjp.ToStringDemo
 
Jim Sandman
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, Jesper !
I had forgotten about putting the path in CLASSPATH at one level up from where the files reside.

Jim
 
He does not suffer fools gladly. But this tiny ad does:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic