Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JDate and GDate

 
Ian Lubelsky
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am currently working on the assignment DaysOld.
I wanted to make sure I had the jr.jar properly set up and wrote the following to test it:



It compiles without any problem (javac -cp "C:\Program Files\Java\jr.jar" DateTest.java). The problem arises when I try to run it, I get the following error:



Is there something I am doing wrong or do I have the jr.jar file not properly setup?

Thanks
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The code itself looks good. My thought is the jar file was not integrated correctly. You might want to try it again.

this or this might help.

Good luck,
Gary
 
Ian Lubelsky
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Gary; but the fault was mine why it wasn't working.
I went back to double check to see if I had properly set the CLASSPATH, when I saw that I had actually set it in the Path by mistake. Fixed that and abredacabra it worked.
 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good job.

Now the interesting question is why did it compile?
Because if you are using a collection and you forget to import it, it won't compile at all. What is the difference?

I'll wait until one of the smarter folks answer to this thread.

 
Ian Lubelsky
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My thinking why it compiled was because it was able to find the jar file in the path, but when I tried to run the script, it was looking in the CLASSPATH and couldn't find anything and gave the error message. Of course I may be wrong, but then again I may be right. I think I just quoted a a Billy Joel song.
 
Mike Simmons
Ranch Hand
Posts: 3090
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It compiled because you told the compiler where the jar was, using the -cp option:

    javac -cp "C:\Program Files\Java\jr.jar" DateTest.java

When you specify the -cp option (or -classpath option, same thing) it ignores your CLASSPATH system property entirely, and just uses whatever path you gave after the -cp.

You can also use a -cp option when you run the program:

    java -cp ".;C:\Program Files\Java\jr.jar" DateTest

When you do this, again, it will ignore your CLASSPATH system property, and just use the path you give it. Note that I added ".;" at the beginning, so that it also finds the current directory. That's usually a good idea.

 
Gary Ba
Ranch Hand
Posts: 161
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now it makes sense.
Thanks Mike!
 
Ian Lubelsky
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the info Mike.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic