Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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

JDate and GDate

 
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
 
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.
 
Rancher
Posts: 3572
39
  • 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.
 
Skool. Stay in. Smartness. Tiny ad:
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