Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / First Aid / August 2007

Tip: Looking for answers? Try searching our database.

Newbie - JAR question

Thread view: 
Lee A. Wentzel - 30 Aug 2007 17:23 GMT
Just created a little Java application which converts degrees Celsius to
Fahrenheit. Uses Swing.  So, if I have a lib folder with the swing.jar on
my desktop it will run.  I know there has got to be a way to include that
folder in the actual Jar.  I've copied it into it, but it still won't
run.  In the META-INF folder in the Jar, I've modified the MANIFEST.MF to
read as follows.

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.6.5

Created-By: 1.5.0_09-b03 (Sun Microsystems Inc.)

Main-Class: learn.CelsiusConverterGUI

Class-Path: swing-layout-1.0.jar

X-COMMENT: Main-Class will be added automatically by build

The Class-Path use to read:

Class-Path: lib/swing-layout-1.0.jar

I am thinking I am on the right track, but it still doesn't work.  Any
help would be appreciated.  Thank you in advance.

Lee
Andrew Thompson - 30 Aug 2007 17:45 GMT
>Just created a little Java application which converts degrees Celsius to
>Fahrenheit. Uses Swing.  So, if I have a lib folder with the swing.jar ..

What 'swing.jar' is that exactly?  AFAIR there was a swing.jar
available from Sun for Java 1.1, as an add-on for the (then
experimental) Swing classes that were included in the J2SE
in Java 1.2.

>..on
>my desktop it will run.  I know there has got to be a way to include that
>folder ..

Folder or jar?  Entire folders or directories of resources
can be included in Jar files, but it does not make sense
to include Jar files in that, since the Java standard
ClassLoader will not load resources inside Jar files that
are elready in Jar files.  Instead, each Jar file needs to
be 'supplied to'/'specified on' the classpath of the
application.

>..in the actual Jar.  I've copied it into it, but it still won't
>run.  In the META-INF folder in the Jar, I've modified the MANIFEST.MF to
>read as follows.
>
>Manifest-Version: 1.0
...
>Class-Path: swing-layout-1.0.jar

So are we referring to 'swing.jar', or 'swing-layout-1.0.jar'
or something else entirely?  Please do not 'paraphrase'
names when posting questions to groups, or you waste
your time, and our bandwidth.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

Lee A. Wentzel - 30 Aug 2007 18:05 GMT
> So are we referring to 'swing.jar', or 'swing-layout-1.0.jar' or
> something else entirely?  Please do not 'paraphrase' names when posting
> questions to groups, or you waste your time, and our bandwidth.

Sorry.  Not "swing.jar" but rather "swing-layout-1.0.jar".  I am getting
the examples from Sun's website.  I'm just trying to understand the inner
workings. Of a JAR file.

If I look in the "swing-layout-1.0.jar" there are two directories.  One
which is "META-INF" and the other is named "org".  In the "org" directory
is the "jdesktop" directory.  In it, is "layout", finally in "layout"
there are a whole bunch of files.

I have seen JAR files out there that don't require library folders or
other things that aren't already included in the initial JAR.  That is
what I am hoping to figure out how to do.  Thank you.

Lee
Lew - 30 Aug 2007 21:19 GMT
>> So are we referring to 'swing.jar', or 'swing-layout-1.0.jar' or
>> something else entirely?  Please do not 'paraphrase' names when posting
[quoted text clipped - 12 lines]
> other things that aren't already included in the initial JAR.  That is
> what I am hoping to figure out how to do.  Thank you.

If your layout JAR is in the same directory as your custom JAR, the custom JAR
just has to specify the layout JAR in its manifest's Class-Path attribute.

Signature

Lew

Lee A. Wentzel - 30 Aug 2007 22:10 GMT
> If your layout JAR is in the same directory as your custom JAR, the
> custom JAR just has to specify the layout JAR in its manifest's
> Class-Path attribute.

Thank you Lew.
Lee A. Wentzel - 30 Aug 2007 18:25 GMT
Just curious Andrew, did you not understand what I was asking?  Or just
didn't like the way I asked?  Not that it matters, I was able to figure
this out on my own.

Lee
Lee A. Wentzel - 30 Aug 2007 18:23 GMT
I've figured it out.  I took the "org/jdesktop/layout/files..." and moved
it into my original JAR file.  I then changed the the MANIFEST.MF as
follows.

Manifest-Version: 1.0

Ant-Version: Apache Ant 1.6.5

Created-By: 1.5.0_09-b03 (Sun Microsystems Inc.)

Main-Class: learn.CelsiusConverterGUI

Class-Path: org/jdesktop/layout/

X-COMMENT: Main-Class will be added automatically by build

Tried running my JAR and it worked this time.  So... I guess I figured it
out.  Thanks any ways.

Lee
a24900@googlemail.com - 30 Aug 2007 20:34 GMT
On Aug 30, 7:23 pm, "Lee A. Wentzel" <lee.went...@sbcglobal.net>
wrote:
> I've figured it out.

No, you didn't. This is not a general solution, this is an ugly hack,
and does not scale.

Your mistakes

You used a non-standard GUI element without recognizing that it wasn't
part of standard Java.

You don't understand the Java classpath, the Manifest classpath and
the way Java searches for classes.

You might have done a copyright violation. I don't know the license of
that swing-layout-1.0.jar stuff. It might be that the license
prohibits copying its classes it into an own application. But even if
it is OK for swing-layout-1.0.jar you will sooner or later want to use
a library which doesn't allow such things.

And finally, you trashed Andrew when he was trying to
help.
Lee A. Wentzel - 30 Aug 2007 21:16 GMT
> No, you didn't. This is not a general solution, this is an ugly hack,
> and does not scale.

Ok, "does not scale" means what?

> Your mistakes
>
> You used a non-standard GUI element without recognizing that it wasn't
> part of standard Java.

It is an example from Sun's website the creators of Java if I am not
mistaken. (Although I most likely am.) If it isn't standard, what would
be the correct way to do a GUI? I am a complete newbie to Java which is
why I was asking for assistance.

> You don't understand the Java classpath, the Manifest classpath and the
> way Java searches for classes.

You're right. I don't. Hence my calling myself a newbie.

> You might have done a copyright violation. I don't know the license of
> that swing-layout-1.0.jar stuff. It might be that the license prohibits
> copying its classes it into an own application. But even if it is OK for
> swing-layout-1.0.jar you will sooner or later want to use a library
> which doesn't allow such things.

Which is why I turned to this newsgroup asking for assistance. Which is
why I clarified I am a complete newbie to JAVA.

> And finally, you trashed Andrew when he was trying to help.

I don't believe I treated him any differently then he treated me. To
quote Andrew "you waste your time, and our bandwidth."

My question to him was legitimate.  Did he not understand what I was
asking for? I have been getting help from various news groups for over a
decade. Some are very helpful, others are full of pompous a.ses who like
to stroke their egos and let you know how worthless you are.

My intentions were to get help with a language which seems like the best  
way to go given it's portability, not start a flame war about how I don't
know how to ask a question intelligently. I don't. I don't know the
terms. I am learning by 'hacking' as you suggested. That is how I have
learned every language I have dabbled in.

So if we are done pointing out my short comings, please set me straight.
What is a "standard" library to use for a GUI? How do I build the jar so
that it doesn't need additional libraries? Where can I find better
examples then Sun's website to learn Java?

Thank you in advance.

Lee
RedGrittyBrick - 30 Aug 2007 23:37 GMT
>> No, you didn't. This is not a general solution, this is an ugly
>> hack, and does not scale.
>
> Ok, "does not scale" means what?

I guess a24900 means that unpacking Jars and repacking their contents
into your own jar gets a bit tedious if you have many jar files you need
to use. The easier way is to *list* the other jars in the manifest of
your application's jar.

>> Your mistakes
>>
[quoted text clipped - 5 lines]
> would be the correct way to do a GUI? I am a complete newbie to Java
>  which is why I was asking for assistance.

I think the swinglayout jar contains the class files for the GroupLayout
layout manager. If your JRE doesn't include GroupLayout then I guess it
isn't quite "standard" in the sense I would understand it.

http://wiki.netbeans.org/wiki/view/FaqPackagingMatisseBasedProjects

If you use one or more of the, er, more standard layouts, you wouldn't
need to include another jar in this way. The layouts I am thinking of
are FlowLayout, BorderLayout, BoxLayout, GridLayout and GridBagLayout.

I'm not saying these are more "correct", just more commonplace IMHO.

>> You don't understand the Java classpath, the Manifest classpath and
>>  the way Java searches for classes.
>
> You're right. I don't. Hence my calling myself a newbie.

There's no shame in being a newbie, I still consider myself a bit of a
newbie to Java. I try not to let my laziness be too obvious though :-)

>> And finally, you trashed Andrew when he was trying to help.
>
> I don't believe I treated him any differently then he treated me.

I find that reacting to abhorrent behaviour by behaving abhorrently
isn't usually useful. YMMV.

> To quote Andrew "you waste your time, and our bandwidth."

To be fair to Andrew what he said was "Please do not 'paraphrase'
names when posting questions to groups, or you waste your time, and our
bandwidth."

Note the word "Please".

Note that he is saying that *if* you say "swing.jar" when you mean
"swinglayout.<version>.jar" then you are going to confuse or mislead
people who are trying to help you.

> My question to him was legitimate.

Wasn't his answer legitimate? I think he did pretty well to guess your
problem and point you at some solutions?

> Did he not understand what I was asking for?

It sounded like he wasn't sure. I wasn't.

> I have been getting help from various news groups for over a decade.
>  Some are very helpful, others are full of pompous a.ses who like to
>  stroke their egos and let you know how worthless you are.

I say don't worry about the pomposity of a.ses. Let them stroke their
egos whilst you pick out any valuable bits of advice from their
postings. Ignore everything else. Win-Win. YMMV.

Like Andrew, I am keen to help people in this newsgroup. I have less
expertise but nonetheless I try to help. Sometimes I can't help because
the question is unclear. This can be frustrating for the would-be
helper. It is then natural to think - gee, If this poster had spent a
few more minutes composing a better question I'd be able to understand
and help solve the problem.

> My intentions were to get help with a language which seems like the
> best way to go given it's portability, not start a flame war about
> how I don't know how to ask a question intelligently. I don't.

Have you re-read http://www.catb.org/~esr/faqs/smart-questions.html
recently? I find it useful.

> I don't know the terms. I am learning by 'hacking' as you suggested.
>  That is how I have learned every language I have dabbled in.
>
> So if we are done pointing out my short comings,

I don't suppose we are :-) In your shoes, I'd try not to let it bother me.

> Where can I find better examples then Sun's website to learn Java?

I don't know anywhere that's universally better. That doesn't mean you
can't find some bad examples at Sun's websites too :-)
Andrew Thompson - 31 Aug 2007 03:08 GMT
...
>>> And finally, you trashed Andrew when he was trying to help.
>>
>> I don't believe I treated him any differently then he treated me.
>
>I find that reacting to abhorrent behaviour by behaving abhorrently
>isn't usually useful. YMMV.

Huhh?  I will have to trawl this thread more carefully, but
I did not realise anybody was being abhorrent!

Lee posed a valid question back to me, based on my
(slightly 'terse') comment about being accurate.

Note that although I took care to add 'please' before it,
the comment I made was not stated in the usual
'super nice' way that we might hope to see on
comp.lang.java.help, a group on which it is generally
expected that if someone cannot say something nice,
most contributors would prefer them to say nothing at
all.

As far as Lee's reply (which I will requote)..

(Lee)
>>Just curious Andrew, did you not understand what I was asking?  

I was 99%+ confident that you are referring to the second
listed jar, but wanted to make a point about being accurate.
Being accurate might get both sooner, and more replies,
to any future messages.

>>Or just didn't like the way I asked?  

Yes and no.  Your post was *mostly* clear and specific,
but fell down on that one uncertainty.  It is a general
principle when debugging things to "copy/paste" input,
output and code, otherwise there are too many variables,
too many guesses, to hope to solve most problems.

The recommendation to include all information literally
was not something I 'did not like' as such, but could
recognise that it might limit the replies, or the usefulness
of replies.

To be honest, I guess most people would have guessed
the two jar's were the same, but the point is to tack it
down so far, they do not *have* to guess.

>> Not that it matters,..

I suspect you and I are less affected by it, than some
of the other people replying to the thread!
To be honest, I cannot quite understand why your words
might have attracted the comment 'abhorrent', though
perhaps mine might have been put even more diplomatically
for this group.

And as an aside, in marked contrast to most people who
might be prompted to wonder what was going through my
head when replying, you asked.  

Very sensible, given the 'most people' mentioned above
would either 'retreat in embarrassment' and never post
again, or launch back into the group with a vindictive
reply telling me what an 'a!s-hole' I am.

>> .. I was able to figure this out on my own.

Other people seem to have 'picked up the ball..' on
the technical matters, so I will not revisit that side.

Signature

Andrew Thompson
http://www.athompson.info/andrew/

RedGrittyBrick - 31 Aug 2007 10:28 GMT
> ..
>
[quoted text clipped - 7 lines]
> Huhh?  I will have to trawl this thread more carefully, but
> I did not realise anybody was being abhorrent!

a24900: "[Lee] trashed Andrew".
Lee:    "I treated [Andrew] [as] he treated me"
        Paraphrasing:
        "I trashed Andrew because he trashed me"
RGB:    "I find retaliating in kind isn't useful".

I didn't think you were being abhorrent. Even if you were, as a
recipient, I hope I'd not be equally abhorrent when replying.

In future I shall be more careful how I phrase my trite homilies :-)
Mark Space - 31 Aug 2007 18:39 GMT
> that it doesn't need additional libraries? Where can I find better
> examples then Sun's website to learn Java?

I found O'Reilly's _Learning Java_ to be a pretty good place to start.
Perversely, the Sun Tutorial is better as a bank of examples for those
who already know Java than it is as a tutorial for those who are just
starting.

With the O'Reilly book, Sun's tutorial for examples, and Sun's (or a
local copy of) Java reference, you can get most anything done.

For libraries, that's just experience.  Always check out whether a lib
is part of the standard distribution, and if it's not, then how hard is
it going to be for the user to get at it.  You'll mess this up a few
times before you learn all the nooks and crannies of the language and
it's various versions and libraries.  No worries, it's all learnin'.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.