• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problems with OOP-1 ...

 
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi there,

perhaps somebody can help me out here ...
If I compile like this:

javac -casspath c:\myjava\jr.jar DaysOld.java

I get no error msgs.

If I then run the class with

java -casspath c:\myjava\jr.jar DaysOld 200-1-1

I get an error msg:
Exception in thread "main" java.lang.NoClassDefFoundError: DaysOld

If I un-jar the jar in the same directory I have no problems compiling and running without the classpath option. But this can't be the solution ...

Anyway I'll carry on with the un-jar-ed version for now, but I could do with some help here.

Thanks in advance,
Stuart
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you run with the classpath option, you probably need to include the "current directory", designated by a dot or alternatively the current classpath settings using %CLASSPATH% (windows notation).
 
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this:

 
Stuart Goss
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the help!

Here is my "solution":

java -classpath %CLASSPATH% DaysOld 2000-1-1

Strangely enough, it will not work without this, unless I unpack the jar file.

> echo %classpath%
C:\Programme\Java\jdk1.5.0\jre\lib\rt.jar;
C:\Programme\Java\jdk1.5.0\lib\tools.jar;
"k:\eigene dateien\myjava";
"k:\eigene dateien\myjava\jr.jar";

BTW: I am not reeeeaaaaally happy with this solution ...
[ January 24, 2006: Message edited by: Stuart Goss ]
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just my two cents.

rt.jar and tools.jar are not required to be included in the CLASSPATH variable.

Is "k:\eigene dateien\myjava" your current directory where DaysOld.class is stored? If so, you can replace it with a dot.

Here is what I would do:

[ January 24, 2006: Message edited by: Joyce Lee ]
 
Stuart Goss
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joyce,

I like your solution better. I'll take the rt.jar and tools.jar out of the classpath variable and (as you suspected correctly) I'll replace the "k:\eigene dateien\myjava" with ".".

Thanks again,
Stuart
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Stuart, I just realized a mistake in my previous post.

With the CLASSPATH variable updated, it is not necessary to include -classpath in the java command line. It should be

 
Stuart Goss
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Joyce,

it works exactly the way you suggested

But, do I really need to "set CLASSPATH" everytime?

Thanks again!
Stuart
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alternatively, you can set your environment variable CLASSPATH. How you do this depends on your operating system.
 
Stuart Goss
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I tried that, Marilyn. But it just didn't help ...

The other solution sounds fine though, ... for now
 
Marilyn de Queiroz
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you set your environment CLASSPATH variable to look just like the one you are using in the "set" command? i.e. CLASSPATH=".;k:\eigene dateien\myjava\jr.jar;"

By the way, you don't need the ending semicolon.
 
Joyce Lee
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Stuart,

On Windows system, one may need to reboot the system after making changes in the Environment Variables to allow it to take effect.

1. Set/edit the CLASSPATH in the Environment Variables.
2. Reboot the system
3. Open a command prompt and check if the CLASSPATH has been updated correctly


Should see something like this:

4. Try the java command:


Joyce
[ January 25, 2006: Message edited by: Joyce Lee ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic