File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes creating a package of classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "creating a package of classes" Watch "creating a package of classes" New topic
Author

creating a package of classes

Cyrus Serrano
Ranch Hand

Joined: Sep 29, 2003
Posts: 137
can anyone give me an introductory on how classes can be package, please...
thanks...
Cyrus
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Hi

http://java.sun.com/docs/books/tutorial/java/interpack/packages.html

-Sainudheen
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Sometimes when folks are talking about packaging some Java classes, they're talking about putting them together in a JAR file. Take a look at The Jar Files Trail of Sun's Java Tutorial for such instructions and information.


[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Jacquie Barker
author
Ranch Hand

Joined: Dec 20, 2000
Posts: 201
Determine the name of the package, then in each class that is to belong to that package, put in the statement:
package com.mypackage; // or whatever the name is to be
ahead of all import statements.
When you compile your source code, use the command:
javac -d . *.java
to cause all of the .class files to be stored in a subdirectory beneath the working directory whose path matches the path name; in the case of my example above, if my source code were in a directory called /mycode, then the .class files would wind up in a directory called /mycode/com/mypackage.
Next, use the following command
jar cvf somename.jar com
to bundle up, as a Java archive, all of the code in your package.
Anyone wanting to use your package would have to (a) import com.mypackage.* and (b) have your jar file in their classpath.
Hope this helps!


Author of Beginning Java Objects, Beginning C# Objects, and Taming the Technology Tidal Wave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: creating a package of classes
 
Similar Threads
import packages?
Servlet [servlet-name] is currently unavailable
question about static members
Default package
what's the purpose of private and protected access modifiers?