
-----------------------------------
Homer_simpson
Fri Mar 05, 2004 6:38 pm

importing files
-----------------------------------
say i got this file i've made so i can import it later where do i gotto save it? and how do i import it?

-----------------------------------
rizzix
Fri Mar 05, 2004 6:52 pm


-----------------------------------
k u don't need to use the import keyword unless ur code is in a package.

now after u compile all ur code. u'll get the respective classes.
so if these classes compose ur library. and u wish to use them in code els where. all u need to do is copy those .class files into the same directory of ur current project. then simply compile ur code like this:
javac -cp . MyTestfile.java

note, u don't really need add any extra lines into ur code to use those classes. its all automaticly taken care of.

-----------------------------------
Homer_simpson
Fri Mar 05, 2004 6:55 pm


-----------------------------------
yup! thx alot man!

-----------------------------------
rizzix
Fri Mar 05, 2004 6:56 pm


-----------------------------------
also it might sometimes make it easier to package a library of classes into a .jar archive. 

and at times if it is soo frequently used u can also drop that .jar (or .class files) into the ext dir in ur java root directory.

-----------------------------------
Homer_simpson
Fri Mar 05, 2004 8:15 pm


-----------------------------------
not a bad idea...
only if i knew how to turn my files into a package :S

-----------------------------------
rizzix
Sat Mar 06, 2004 1:58 pm


-----------------------------------
it is really easy.  all u need to do is add the line package name_of_package; at the top of each file to denote that those classes defined in those .java files to be in that perticular package. 

next u compile these files

then u move the respective .class files into a new directory that has the same name as that of the package.

now go and download the jarmaker utility i created (somewhere in the java submissions).

now create a blank file with the word "manifest" in it's name.

drag both the directory and that file onto the jarmaker, it should generate a .jar file.

ur done. ;)

-----------------------------------
rizzix
Sat Mar 06, 2004 2:19 pm


-----------------------------------
also note: compiling against a jar archive has a slightly different syntax:
javac -cp myarchive.jar;. my_java_source_file.java
