Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 importing files
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Homer_simpson




PostPosted: Fri Mar 05, 2004 6:38 pm   Post subject: 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?
Sponsor
Sponsor
Sponsor
sponsor
rizzix




PostPosted: Fri Mar 05, 2004 6:52 pm   Post subject: (No subject)

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:
code:
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




PostPosted: Fri Mar 05, 2004 6:55 pm   Post subject: (No subject)

yup! thx alot man!
rizzix




PostPosted: Fri Mar 05, 2004 6:56 pm   Post subject: (No subject)

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




PostPosted: Fri Mar 05, 2004 8:15 pm   Post subject: (No subject)

not a bad idea...
only if i knew how to turn my files into a package :S
rizzix




PostPosted: Sat Mar 06, 2004 1:58 pm   Post subject: (No subject)

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. Wink
rizzix




PostPosted: Sat Mar 06, 2004 2:19 pm   Post subject: (No subject)

also note: compiling against a jar archive has a slightly different syntax:
code:
javac -cp myarchive.jar;. my_java_source_file.java
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: