File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Cattle Drive and the fly likes JDate and GDate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » This Site » Cattle Drive
Bookmark "JDate and GDate" Watch "JDate and GDate" New topic
Author

JDate and GDate

Ian Lubelsky
Ranch Hand

Joined: Feb 10, 2010
Posts: 49
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

Joined: Oct 23, 2009
Posts: 150

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


star chaser..
Ian Lubelsky
Ranch Hand

Joined: Feb 10, 2010
Posts: 49
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

Joined: Oct 23, 2009
Posts: 150

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

Joined: Feb 10, 2010
Posts: 49
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

Joined: Mar 05, 2008
Posts: 2969
    
    9
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

Joined: Oct 23, 2009
Posts: 150

Now it makes sense.
Thanks Mike!
Ian Lubelsky
Ranch Hand

Joined: Feb 10, 2010
Posts: 49
Thanks for the info Mike.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDate and GDate
 
Similar Threads
Posting Density Stastics
Calculate date
Do I need to reinstall Java?
Main not found, but it exists!
java command not finding jar file