Java classes

buc99

Don't Tread on Me!
I'm just begining to learn Java.

Where are the Java Classes located?
Where are the Java Packages located?
Do these include java.sql or a similar JDBC SQL API?
Does Apple include the full Java API?
Is there any documentation on where all of the Java guts are located in OSX?

Thanks.:)
SA
 
Get JDBC(java.sun.com) or whatever classes you can get and dump them in /Library/Java/Extentions/ , then they are available for access from wherever.
 
Java is not like the others.


Java depends on an environment variable called CLASSPATH, that variable tells the Java Virtual Machine (the thing that runs Java, invoked by the command "java" on the commandline) where all Java-classes are located.

Classes can be separate .class-files in directories, or bundled together in .jar- (or .zip-)files.

To fully explain what packages really are, I could go on and on, but this is what packages are in the file-system (since that seems to be more to the question): Packages are directory trees with classes in the right directories. You were interesed in java.sql, that would be the "java/sql" directory (most probably inside a .jar-file).

So where do the classes reside? Well first of all there in a .jar-file, and the .jar-file can be located anywhere as it's in the classpath.

To set up the CLASSPATH variable to that it includes a specific .jar-file do this: go to the terminal and type "pico ~/.tcshrc", you might have edited this file at another time, if not, it is created. Then you add a line that says:

Code:
setenv CLASSPATH "/path/to/jar/file.jar"

If you want to add another .jar-file or a directory which is the root of a package hierarchy (the directory where the "com" directory is located if your package is called "com.example.java"). Do add this line after the first:

Code:
setenv CLASSPATH "${CLASSPATH}:/path/to/another/jar/file.jar:/path/to/directory"

I have my classes and .jar-files in ~/Library/Java.

/Library/Java/Extensions is for system wide Java extensions, and I think it's only writable by root... I like to keep everything to my home directory, so that I can move that around without breaking anything. My classes goes in my library, "system" classes can go in the system library. Whatever. The benefit of the extensions directory is that you don't have to worry about the classpath.
 
Does the CLASSPATH setting take the place of Extensions?
Do I have to keep a copy of the classes in Extensions in my ~/Library/Java path also?
Or do I just put my new classes in ~/Library/Java and java will recognize both paths?
Would the CLASSPATH in ~/.tcshrc then be:


Code:
setenv CLASSPATH "${ CLASSPATH}:~/Library/Java"

?

Where do I find more java packages? Does the MacOSX version of java come with an SQL Package, or do I need to download my own?

Thanks.
SA:)
 
What went wrong?

I added the following to my .cshrc file:

Code:
setenv CLASSPATH "${CLASSPATH} :/User/username/Library/Java"

And when I open a new terminal window I get the following message:

CLASSPATH: Undefined variable.

Where did I go wrong?

Thanks.:)
SA
 
well, extensions take precedence over the CLASSPATH, but you shouldn't include jar-files in your extensions-directory in your classpath.

x probably includes java.sql, you could test that easily like this (save code as SQLTest.java and fix any errors...):

Code:
import java.sql;

public class SQLTest {

    private java.sql.Date test;


    public SQLTest( ) { test = new java.sql.Date(0); }

}

Compile by typing javac SQLTest.java in a terminal (cd to the directory where the file is first...)

If this compiles, you have java.sql installed. Otherwise get it from http://java.sun.com. You could also test this by "jar -tf filename | grep 'java/sql'" if you replace "filename" with the path to the jar-file containing the java base classes (located somewhere in /System/Library/Frameworks/JavaVM.framework/ dunno where (not on my X-box now).



buc99: do it like this:

Code:
setenv CLASSPATH "~/Library/Java"

the "${CLASSPATH}:~/Library/Java" is only if you have already set the variable (sorry if that was unclear). The "~" means your home directory ("/Users/username/")

Note however that the directory must exist and that ~/Library/Java won't include any jar-files in that directory, they must be added separately:

Code:
# CLASSPATH has already been set above
setenv CLASSPATH "${CLASSPATH}:~/Library/Java/jarfile.jar"

You could also do it all at once:

Code:
setenv CLASSPATH "~/Library/Java:~/Library/Java/jarfile.jar"

And you can add more jar-files to the end of the line, separating each path with a colon (":").


apple includes all of the J2SE 1.3 API. It is all located in /System/Library/Frameworks/JavaVM.framework (even the source-code for the java.* packages should be there in a file called src.zip or similar.



theo/iconara
 
Straight from Apples development site and their pdf Java Development on Mac OSX:
In Mac OS X, you treat classpath the way you would in any BSD shell. You can use
setenv classpath newClasspathAddition to add to the classpath for the duration of
the current Terminal session for that particular Terminal window. You still have to
explicitly add a reference to this variable when compiling by typing javac
-classpath %CLASSPATH filename. You can determine the current value of your
classpath with the command echo $CLASSPATH.

So I changed the setenv line in my .cshrc to the following:

Code:
setenv CLASSPATH /Users/username/Library/Java

I now get no error when starting a new terminal and echo $CLASSPATH returns the correct value.

Am I correct?

Thanks.:)
SA
 
try quoting the path:

Code:
setenv CLASSPATH "~/Library/Java"


shouldn't make a difference though... what error do you get? the line you use seems correct to me. try executing it directly in your shell and see if you get an error there, if not, then something else is wrong.

which shell are you using? csh? if your error persist try switching to tcsh or if you're already use it, at least use the .tcshrc config file.

theo
 
Everything is working fine now. I also found the java.sql class in the following directory:

/System/Library/Frameworks/JavaVM.framework/Versions/1.3.1/Classes/classes.jar

so everything is cool now.

Thank you all for your help. I wished Apple or someone else would give a little more detail on the setup of Java on OSX. Even though OSX is Java compliant, Java is not setup like a regular Unix. And all of the documentation I've found have been for the most part either Unix or Windows geared. So people, like myself, who are just now stepping into the programming arena will have a difficult time understanding this and will become frustrated easily. I will add this info to my Tip database which I plan to put on the web one day for everyone.

Thanks Again.:)
SA
 
Back
Top