How to create a JAR file

S

Samar Hossam

Dear everyone,
I need to write a method that takes a source directory and jars its
content. I wrote the following:
public static void jar(String sourceDir,JarOutputStream out,String
parent){
try {
// get a list of files from the current directory
File f = new File(sourceDir);
String files[] = f.list();
// update the parent
if (parent != ""){
parent = parent + File.separatorChar;
}
File tempFile;
BufferedInputStream origin = null;
byte data[] = new byte[2048];
for (int i=0; i<files.length; i++) {
System.out.println("Adding: " + files);
tempFile = new File(sourceDir +File.separatorChar + files);
if(tempFile.isFile()){
FileInputStream fi = new FileInputStream(sourceDir +
File.separatorChar + files);
origin = new BufferedInputStream(fi, 2048);
JarEntry entry = new JarEntry(parent + files);
out.putNextEntry(entry);
int count;
while((count = origin.read(data, 0, 2048)) != -1) {
out.write(data, 0, count);
}
origin.close();
}
else{
JarEntry entry = new JarEntry(parent + files + File.separatorChar);
out.putNextEntry(entry);
jar(sourceDir + File.separatorChar + files,out, parent + files);
}
}
} catch(Exception e) {
e.printStackTrace();
}
}

The problem with the code is the following:

1. Each subdirectory contains an extra empty file
2. If you try to extract a jar file created by this method. The entry
of a subdirectory is considered as a file not a directory.
3. I don't know how to create the META-INF folder

I would appreciate your help sooooo much. Regards, Samar
 
S

Samar Hossam

Hi Andrew
How many groups do you intend to multi-post this
question to Samar? Please don't multi-post.

Well, I urgently needed help concerning the posted problem. That's why
I sent it to two groups only. (comp.lang.java.programmer &
comp.lang.java.help)

Besides, it is not my problem that u've subscribed to several groups.
Finally, your reply to someone in need was veryyyyyyyyyyyy mean.

Samar
 
A

Andrew Thompson

Hi Andrew


Well, I urgently needed help concerning the posted problem.

That is nobody's problem but yours.

These are discussion forums, not your personal
help-desk for urgent problems.
..That's why
I sent it to two groups only.

When (rarely) posting to multiple groups,
x-post rather than multi-post..
..(comp.lang.java.programmer &
comp.lang.java.help)

Your question is best suited to c.l.j.help at this stage.
Besides, it is not my problem that u've subscribed to several groups.
Finally, your reply to someone in need was veryyyyyyyyyyyy ..

Please fix your

Your pitiful pleas are very boring.
 
T

Thomas Weidenfeller

Samar said:
Well, I urgently needed help concerning the posted problem.

Then pay someone to do your work. We are not your free helpdesk.

/Thomas
 
S

Samar Hossam

What's wrong with you guys?

I was asking something, if you don't wanna answer, simply ignore the
message. Is that so difficult to do?

And if you don't know the answer, just shut up. There's no point
behind this stupid game we are palying here.
 
T

Thomas Weidenfeller

Samar said:
What's wrong with you guys?

Nothing. But there is a lot wrong with you. You are not playing by the
rules and you are clue-resistant. It is you who demands our time, but
can't help to insult us. Looking at the thread, your behavior didn't
provide you with too many answers, did it? So apparently your strategy
didn't work out.
And if you don't know the answer, just shut up.

Oh, I know the answer. I even have some code lying around at home doing
what you want. But I can't be bothered for the live of me to dig it out
for you. Guess why?

/Thomas
 
A

Andrew Thompson

I was asking something,

You asked it first on c.l.j.help.
..if you don't wanna answer, simply ignore the
message.

I did. I have to make value calls with every post.
That day, your question just did not make the cut.
..Is that so difficult to do?

No, it's easy.

When you popped up again on this group, I decided to give
you the advice not to multi-post, which is something I do
to ensure the groups do not become infested by yelling idiots
that have an over-developed sense of their own importance.

I also decided that if you responded in a sensible manner,
I would take another look at your original question, back
on c.l.j.help.
And if you don't know the answer, just shut up.

Bwaaa-Ha-Ha haaaHa, Ha, ha.. you're funny.
...There's no point
behind this stupid game we are palying here.

If you had the sense to lurk before posting, you
would realize how wrong you were.

Good luck with that problem..
 
S

Samar Hossam

When you popped up again on this group, I decided to give
you the advice not to multi-post,

It is very nice of you to give me an advice but you just lack the way
you say it.
which is something I do to ensure the groups do not become infested
by >yelling idiots that have an over-developed sense of their own
importance.

Again, this is very impolite of you.
I also decided that if you responded in a sensible manner,

How do you expect that, when you make fun of me?
I would take another look at your original question, back on c.l.j.help.

I don't need your help. Not now, nor for ever.
Good luck with that problem..

Thank you so much... I have already solved it.
 
O

Oscar kind

Samar Hossam said:
by >yelling idiots that have an over-developed sense of their own
importance.

Again, this is very impolite of you.

Not at all: the "yelling idiots" are impolite.
The one speaking sternly to them is providing a community service.

Let's face it: usenet is a community. And since this newsgroup is not
moderated, anyone can post whatever he'she likes. This also means, than
this newsgroup can become swamped by loafers, spammers and other undesired
folk.

To ensure that this newsgroup remains useful, some nice people take it
upon themselves to:
- Remind people of netiquette
- Ask people do their homework (this also goes for non-students!)
- Ask for smart questions others can also learn from

I hold these people in high regard.
 
A

Andrew Thompson

It is very nice of you to give me an advice but you just lack the way
you say it.

What?
"How many groups do you intend to multi-post this
question to Samar? Please don't multi-post.
<http://www.physci.org/codes/javafaq.jsp#xpost>"

Which part did I swear at you, or yell at you?
Where did I tell you to do, or not do, anything?

Which bit offended you, and how?
by >yelling idiots that have an over-developed sense of their own
importance.

Again, this is very impolite of you.

Impolite is in the eye of the beholder, and you had
already expressed your impoliteness in a number of ways.

a) not lurking before posting
b) not reading the FAQ
c) multi-posting
d) marking your message as urgent
e) arguing with people offering advice
Thank you so much... I have already solved it.

Good to see that 'I am an island' spirit, you are sure going
to need it while carrying that huge chip on your shoulders.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,114
Latest member
GlucoPremiumReview
Top