hello everyone, I'm hoping that someone can help me with my little problem. I new to Java and somewhat new to the Mac platform. I'm learning Java through the (Sams Teach yourself Java 6 in 21 days)I'm on day 6: Packages, Interfaces, and Other Class Features, and I'm trying to understand the Java Classpath. If someone could tell me how you go about doing this on a Mac I would be most greatful. I'm running all my Java applications from the terminal and not an IDE.
What version of Java are you running? You should be able to find that from the command line by writing
java -version javac -version
and the answer to both ought to be more-or-less the same. You don't have to do anything with your CLASSPATH for recent versions of Java on PCs (neither on Windows nor on *nix), so you probably don't have to set a CLASSPATH on a Mac either. You may need CLASSPATH options when you start using large applications, but then you set the CLASSPATH at the command line.
I found this by googling; I hope it is of some use; if you need more information don't hesitate to ask again.
And have a look at our Mac forum because there might be something useful there.
First just wanted to say thank you to everyone, I've made some head way with my problem, but I've run into another one regarding the same topic.
Ok here it goes, this app I'm working on draws on two classes that I have created in a custom package called (org.cadenhead.ecommerce). I created my package directory as follows:
main Java folder is called (J21work), package folder is called (giftstore), in giftstore I have (bin) & (src), I created my java files in (src) and compiled the first by doing "javac -d bin src/org/cadenhead/ecommerce/Item.java" all went well.
The second one I compiled by doing: "javac -d bin -sourcepath src src/org/cadenhead/ecommerce/Storefront.java" again all went well.
Now I'm trying to compile the app portion (I guess you'd call it that) called (GiftShop)which is located in (J21work/temp) and I'm not having any luck, I keep getting an error message saying that my package (org.cadenhead.ecommerce) doesn't exist.
Each of my class files have (package org.cadenhead.ecommerce) in them and in the main class (GiftShop) I do have the (import org.cadenhed.ecommerce).
I have an idea, but before I go and try it, I wanted some input from more experienced people. My idea is, since I have the two supporting class files in (giftstore) I should have written the package and import as (package giftstore.org.cadenhead.ecommerce) & (import giftstore.org.cadenhead.ecommerce).
Am I on the right track, or am I still missing the boat [ September 27, 2008: Message edited by: Paul Maxfield ]
So your current directory (the one from which you're compiling) is J21work/temp, right? In that case, the relative path to your package org.cadenhead.ecommerce is up one level (to J21work) and then in bin." So try adding the classpath flag -cp ../bin to your compilation command. (Note: The double dots (..) should bring you up a level.)
Edit: Whoops. I missed the "temp" part when I first replied. [ September 27, 2008: Message edited by: marc weber ]
"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer sscce.org
users/paulmaxfield/J21work/giftstore from (giftstore) I have src/org/cadenhead/ecommerce (which has the 3 .java files of "item","storefront","giftshop"
I've managed to compile both item, and storefront into the bin folder of giftstore, (but I'm trying to compile "giftshop.java" into temp witch is located in users/paulmaxfield/j21work/temp (I'm going on the recommendation of the book I'm studying out of that says that it may not work if I try to compile this app in the same bin folder that holds the two support classes)
So I'm trying to figure out the "javac" command that compiles the GiftShop into the "temp" folder. Then I'm trying to figure out the "Java" command that will run this thing.
sorry, programming is just really new for me. I understand what you're saying with the ../ I just don't get how to put it all together