Solved

Creating Packages and then adding them to a Zip File...

Posted on 1998-07-27
2
178 Views
Last Modified: 2010-03-30
I have a two part question.
I know how to create a package by using the "package" statement.
My question is can you keep .java code in its own file system(directory) and compile it so the resulting package is put into a common directory?  

I am trying to create packages and have them put into a common file system.  The only way i know how to do this is by putting the .java code into this common directory and compile it.

The reason for this is so i can zip all the classes and add them to one common class directory.

My second question is:  
Does anyone have an example of a makefile that will compile .java code then put it into a .zip file?

thanks in advance!!!!!!!!!!!!!
0
Comment
Question by:jefftk99
2 Comments
 
LVL 5

Accepted Solution

by:
msmolyak earned 50 total points
ID: 1228528
I am not sure I fully understand the issue.

You compile java source with javac command which has -dir flag. You can use that flag to tell it where to position the .class files. The class file has to be in the directory structure matching its package name. If the package name is com.acme.mypackage than the class file should be in the com\acme\mypackage directory under some directory on the class path.

If you want to create a ZIP archive it is fine too. Make sure the directory path of your class file in the archive matches its package name. I use WinZip to create archives (I do not think this can be done from a make file). PkZip probably allows that. You can use JAR command to create an archive, but I found this command rather inflexible. The syntax is

jar -cvf jarfile_name classfile_names

You have to run JAR from the directory at the top of the package hierarchy (that is the one containing the com directory in my example). Let me know if I did not answer your question.
0
 

Author Comment

by:jefftk99
ID: 1228529
Thank you.

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
servlet example 11 56
Opening PDF on button click and fill new document 2 54
Facing this issue for maven proxy setting 2 27
java imports not found 4 49
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
This video teaches viewers about errors in exception handling.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question