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 / General / September 2007

Tip: Looking for answers? Try searching our database.

Problem with .jar file

Thread view: 
Luis Angel Fdez. Fdez. - 25 Sep 2007 13:02 GMT
Hi!

 I have two .class files I want to put into a .jar file. I'm using an
external .jar (derby database) file.

 If I run the app like java -cp .:derby.jar app it works.

 Then if I make a jar file with app.class and other.class...

 jar -c -f MyJar.jar META-INF/MANIFEST.MF app.class other.class

 where MANIFEST.MF has...

 Manifest-Version: 1.0
 Main-Class: app

 Then java -jar -cp .:derby.jar MyJar.jar doesn't work... It's not able
to load the jdbc driver.

 I tried, I don't know if it's right, to put derby.jar into MyJar.jar
and added: Class-Path: derby.jar to manifest file, but I get the same
error message.

 What am I doing wrong?

 Thanks in advance.

 Bye!

Signature

Ubuntu (gutsy) (kernel 2.6.22-11-386 i686) GNOME 2.20.0
Intel(R) Pentium(R) M processor 1.60GHz (800.000 MHz) up 1 day, 5:15
Hattrick: Zanzabornín (1457021) X.1762  # Jabber: laffdez@gmail.com
Sokker: C.D. Arrancatapinos (18088) IV.57   # Linux User #99754

Piotr Kobzda - 25 Sep 2007 13:35 GMT
>   Then java -jar -cp .:derby.jar MyJar.jar doesn't work... It's not able
> to load the jdbc driver.

"When you use this option, the JAR file is the source of all user
classes, and other user class path settings are ignored."

Quoted from:
<http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html#-jar>

>   I tried, I don't know if it's right, to put derby.jar into MyJar.jar
> and added: Class-Path: derby.jar to manifest file, but I get the same
> error message.
>
>   What am I doing wrong?

Everything seems to be correct.  But you probably forgot to copy
derby.jar into your jar's location.

If you use it often, you may also copy derby.jar into
<JRE-HOME>/lib/ext/ directory, that way will no longer need to list it
as a class-path entry.

See also:
<http://mindprod.com/jgloss/jar.html#CLASSPATH>

piotr
Piotr Kobzda - 25 Sep 2007 14:04 GMT
>>   I tried, I don't know if it's right, to put derby.jar into MyJar.jar
>> and added: Class-Path: derby.jar to manifest file, but I get the same
[quoted text clipped - 3 lines]
>
> Everything seems to be correct.

Oh, I probably misread you a bit.  You put derby.jar into your jar,
together with your .class files, right?  If so, that's not typical
approach, and as such, may not be considered correct.

OTH, there is a way to make it working.  But it requires writing a
custom ClassLoader (which is rather advanced topic), or using
third-party tools designed to help in preparation of such kinds of
distributions (e.g. One-JAR).

piotr
Andrew Thompson - 25 Sep 2007 14:27 GMT
...
>Oh, I probably misread you a bit.  

I don't think so - at least, not in your 1st reply.

>..You put derby.jar into your jar,
>together with your .class files, right?  

No.  The jar command listed only the 'two classes' the
OP was referring to - no mention of either the derby.jar,
or its (supposed) multitude of classes.

[off-thread]
BTW Piotr - did you notice my post re. the JNLP XSD?
You are mentioned in it (the XSD).  
[/off-thread]

Signature

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

Piotr Kobzda - 25 Sep 2007 15:04 GMT
>> ..You put derby.jar into your jar,
>> together with your .class files, right?  
>
> No.  The jar command listed only the 'two classes' the
> OP was referring to - no mention of either the derby.jar,
> or its (supposed) multitude of classes.

Yes, but the listing of a manifest contents doesn't shows none of a
further steps taken by the OP, mentioned later:
>>>   I tried, I don't know if it's right, to put derby.jar into MyJar.jar
>>> and added: Class-Path: derby.jar to manifest file, but I get the same
>>> error message.

In my first reply I treated the OP's "put" as introduction to the next
comma following part of his sentence.  I realized later, that there is
possibly my mistake, that's why I posted my correction.

But I'm still not really sure what exactly the OP did...

> [off-thread]
> BTW Piotr - did you notice my post re. the JNLP XSD?
> You are mentioned in it (the XSD).

No, not yet.  I'll take a look at it -- thanks for notifying!

> [/off-thread]

piotr
Piotr Kobzda - 25 Sep 2007 15:29 GMT
>>>>   I tried, I don't know if it's right, to put derby.jar into
>>>> MyJar.jar and added: Class-Path: derby.jar to manifest file, but I
>>>> get the same error message.
>
> In my first reply I treated the OP's "put" as introduction to the next
> comma following part of his sentence.

Well, a comma fabricated by me -- the one preceding "and" next to his
"put". ;-)

>> [off-thread]
>> BTW Piotr - did you notice my post re. the JNLP XSD?
>> You are mentioned in it (the XSD).
>
> No, not yet.  I'll take a look at it -- thanks for notifying!

Hmm, I tried to find it, but there is nothing new in the thread you
mention available from my news servers.  The last message from you there
is dated: Sun, 29 Jul 2007 02:20:59 GMT, is that a one you are referring
to?  I missed something?

>> [/off-thread]

piotr
Andrew Thompson - 25 Sep 2007 16:20 GMT
(Andrew T.)
>>> [off-thread]
>>> BTW Piotr - did you notice my post re. the JNLP XSD?
[quoted text clipped - 6 lines]
>is dated: Sun, 29 Jul 2007 02:20:59 GMT, is that a one you are referring
>to?  I missed something?

It seems to be missing from the GG* archive.
I guess from the headers of one of your recent
messages, that you are using GG?

You can see it here.
<http://www.javakb.com/Uwe/Forum.aspx/java-programmer/37099/JNLP-xsd-schema#78b15
89b35520uwe


Note that I had originally credited you for creating
the initial XSD on which I based mine, but now I
look more closely, it seems you simply directed
me to the tool that could do it.  

(shrugs) Same diff,  That initial one I had, was
complete rubbish - your link get me back on track.

* (mutters) Damn them, damn them to hell..

>>> [/off-thread]

My apologies to the OP for this 'off-shoot' thread.
Hopefully it won't need to go on much longer.

Signature

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

Piotr Kobzda - 27 Sep 2007 16:20 GMT
[OT continuation...]

> It seems to be missing from the GG* archive.
> I guess from the headers of one of your recent
> messages, that you are using GG?

No, I'm not.  I'm usually using the news.gazeta.pl, and sometimes
news.task.gda.pl NNTP servers for read/write Usenet access.  They are
simply fastest (and feeds most accurately AFAIK) from where I'm living,
and am typically accessing the Usenet (Zielona Góra in Poland).  I also
rather rarely use freetext.usenetserver.com for read-only access when I
see that discussion is incomplete.  I've never used GG, and if there are
any references to it in my headers, that's most likely because of
referrenig of someone's else posting only (possibly the OP's in the
particular case of this thread).

> You can see it here.
> <http://www.javakb.com/Uwe/Forum.aspx/java-programmer/37099/JNLP-xsd-schema#78b15
89b35520uwe

I've seen that post before, but now it points to a newer version of the
XSD.  It looks nice nice, but I think the Sun shall do that...

I was simply waiting for announcement of it, as promised in your last
post there. :)  So now, I know that it exists, and thanks for that!  But
for those who are still waiting for it, that's rather good idea to do
the same in the appropriate thread as well. :-)

> Note that I had originally credited you for creating
> the initial XSD on which I based mine, but now I
> look more closely, it seems you simply directed
> me to the tool that could do it.

That's what I did.  And I think that's worth (if not required) to
mention that tool's name also within the XSD.

> (shrugs) Same diff,  That initial one I had, was
> complete rubbish - your link get me back on track.

Nice to hear that. :-)

> * (mutters) Damn them, damn them to hell..

Well, as I said, I have no experience with GG, but I think that there is
no big difference in a way it works compared with a way all other Usenet
servers around the world works.  Usenet is based on feeding of a huge
number of messages between servers (a lot of them also), and there is
nothing amazing to me, that some messages arrives in delay, and some
even never.

piotr
Lew - 27 Sep 2007 17:00 GMT
> Well, as I said, I have no experience with GG, but I think that there is
> no big difference in a way it works compared with a way all other Usenet
> servers around the world works.  

Maybe not in its back-end actions, but on the front end there are numerous
reports of difficulties with GG.  Sometimes old messages have disappeared,
sometimes people accidentally post the same message multiple times because of
its interface.  I keep seeing reports of crappy behavior on the part of Google
Groups.

Signature

Lew

Piotr Kobzda - 27 Sep 2007 22:11 GMT
> Maybe not in its back-end actions, but on the front end there are
> numerous reports of difficulties with GG.  Sometimes old messages have
> disappeared, sometimes people accidentally post the same message
> multiple times because of its interface.  I keep seeing reports of
> crappy behavior on the part of Google Groups.

OK, nothing is perfect.  GG is rather big, and relatively new project.
And, as you know, bugs just happens...

Similar problems have happened (and sometimes still happens) with
classic NNTP servers and/or newsreaders.  Most of these "classic" tools
are simply better tested today.  But I'm nearly sure that in near future
GG will work fine...  Don't take me wrong, I'm not connected with Google
in any kind.  I've just heard that there are lot of people working hard
to make GG better.  That's why my guess is, that soon, or latter, people
will forget about all the complains of GG they have today...

piotr
Andrew Thompson - 28 Sep 2007 05:53 GMT
...
> ...But I'm nearly sure that in near future
> GG will work fine...  

How *far* in the future?
<http://groups.google.com/group/Groups-Suggestions/browse_frm/thread/
2a5e4a9399cb8be7/5aa1426f05edc4ed>

That was posted almost 6 months ago, but there
is still no sign of change on that one, single
matter.

>..Don't take me wrong, I'm not connected with Google
> in any kind.  I've just heard that there are lot of people working hard
> to make GG better.  

Yeah.. (wrily) they have some great *marketing*
people working for them.  :-(

Andrew T.
Andrew Thompson - 27 Sep 2007 17:08 GMT
>[OT continuation...]
>
[quoted text clipped - 3 lines]
>
>No, I'm not.  ...

Yeah..  I had a closer look at the headers after I
said that, and realised I probably got them 'a.s
backwards', since I was *reading* the post in GG.

The rest of what you said is of higher technical
interest, and probably best saved for a response
on the appropriate thread, as you suggest further
down in your reply (now trimmed).

I'll get to that later..
[/OT continuation...]

Signature

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

Lew - 25 Sep 2007 15:43 GMT
Luis Angel Fdez. Fdez. wrote:
>>   Then java -jar -cp .:derby.jar MyJar.jar doesn't work... It's not
>> able to load the jdbc driver.

> "When you use this option, the JAR file is the source of all user
> classes, and other user class path settings are ignored."
>
> Quoted from:
> <http://java.sun.com/javase/6/docs/technotes/tools/windows/java.html#-jar>

Luis Angel Fdez. Fdez. wrote:
>>   I tried, I don't know if it's right, to put derby.jar into MyJar.jar
>> and added: Class-Path: derby.jar to manifest file, but I get the same
>> error message.
>>
>>   What am I doing wrong?

> Everything seems to be correct.  

Except for where the other JAR was placed.

> But you probably forgot to copy derby.jar into your jar's location.

In other words, put the other JAR not inside the application JAR but in the
same directory as the application JAR.

Again, read the tools documentation.  RTFM is an amazingly useful approach.
<http://java.sun.com/javase/6/docs/technotes/guides/jar/index.html>

> If you use it often, you may also copy derby.jar into
> <JRE-HOME>/lib/ext/ directory, that way will no longer need to list it
> as a class-path entry.
>
> See also:
> <http://mindprod.com/jgloss/jar.html#CLASSPATH>

These are FAQs.

- Why doesn't `java -cp $somepath -jar foo.jar AppClass' work?
- How do I include other JARs in the classpath for my JAR-packaged application?

RTFM solves both of them.

Signature

Lew

Andrew Thompson - 25 Sep 2007 13:59 GMT
Piotr explained why this fails, and provided one
suggestion to get it working.  Here are a couple
more..

>  If I run the app like java -cp .:derby.jar app it works.

>  Then java -jar -cp .:derby.jar MyJar.jar doesn't work...

1) java -cp MyJar.jar:derby.jar app

2) List the derby.jar in the classpath of the
Manifest of MyJar.jar

3) Launch the project using web start (makes
specifying the main, as well as adding resources -
easy).

HTH

Signature

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

Luis Angel Fdez. Fdez. - 25 Sep 2007 15:22 GMT
El Tue, 25 Sep 2007 13:00:01 +0000, Andrew Thompson escribió:

 Thanks both of you for your answers.

> 1) java -cp MyJar.jar:derby.jar app

 I tried this first and it works. Anyway I'll take a look to the other
answers too.

> 2) List the derby.jar in the classpath of the Manifest of MyJar.jar
>
> 3) Launch the project using web start (makes specifying the main, as
> well as adding resources - easy).

 I don't know what 'web start' is :(, so I guess I don't need it :).
I'll note it down, thoug.

 Bye!

Signature

Ubuntu (gutsy) (kernel 2.6.22-11-386 i686) GNOME 2.20.0
Intel(R) Pentium(R) M processor 1.60GHz (1600.000 MHz) up 1 day, 7:38
Hattrick: Zanzabornín (1457021) X.1762  # Jabber: laffdez@gmail.com
Sokker: C.D. Arrancatapinos (18088) IV.57   # Linux User #99754

Lew - 25 Sep 2007 15:46 GMT
Andrew Thompson escribió:
>> 3) Launch the project using web start (makes specifying the main, as
>> well as adding resources - easy).

>   I don't know what 'web start' is :(, so I guess I don't need it :).
> I'll note it down, thoug.

You don't need it because you don't know what it is yet?

That is a very, very counter-productive attitude.

Perhaps you should research it first before deciding whether you use it.
After all, an informed decision just possibly might be superior to an
uninformed one.

GIYF.

Signature

Lew

Luis Angel Fdez. Fdez. - 25 Sep 2007 16:23 GMT
El Tue, 25 Sep 2007 10:46:47 -0400, Lew escribió:

> Andrew Thompson escribió:
>>> 3) Launch the project using web start (makes specifying the main, as
[quoted text clipped - 6 lines]
>
> That is a very, very counter-productive attitude.

 I know... I was kidding :)

> Perhaps you should research it first before deciding whether you use it.

 I know I should. Anyway I think something starting with 'web' doesn't
fit my needs (I can be wrong, sure).

 I look for some information about it, and it seems it's something big.
And it seems I don't need it.

> After all, an informed decision just possibly might be superior to an
> uninformed one.

 I agree. But I'm in a hurry (what isn't good at all) and I need to
change this application as soon as possible and I want to keep it as
untouched as I can. I know this is not a good idea, but trust, there are
worse things than what I'm doing :(

And thanks for pointing me to the jar FAQ.

Bye

Signature

Ubuntu (gutsy) (kernel 2.6.22-11-386 i686) GNOME 2.20.0
Intel(R) Pentium(R) M processor 1.60GHz (1600.000 MHz) up 1 day, 8:35
Hattrick: Zanzabornín (1457021) X.1762  # Jabber: laffdez@gmail.com
Sokker: C.D. Arrancatapinos (18088) IV.57   # Linux User #99754

Roedy Green - 26 Sep 2007 00:07 GMT
On Tue, 25 Sep 2007 12:02:46 +0000 (UTC), "Luis Angel Fdez. Fdez."
<laffdez@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>  Manifest-Version: 1.0
>  Main-Class: app

Give your class a decent name, with lower case package name, and upper
case first letter of the class name.

Nobody would likely test jar.exe to make sure it works with code like
yours.

Also pick a name that hints at what it does. "App" gives no clue.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 26 Sep 2007 00:37 GMT
On Tue, 25 Sep 2007 12:02:46 +0000 (UTC), "Luis Angel Fdez. Fdez."
<laffdez@gmail.com> wrote, quoted or indirectly quoted someone who
said :

>  If I run the app like java -cp .:derby.jar app it works.

When you build the jar, you either want to:

1. include the contents of derby.jar
see http://mindprod.com/jgloss/jarexe.html

2. put derby.jar in the ext directory.  See
http://mindprod.com/jgloss/ext.html
This is the easiest technique and the one I use personally.

3. create a manifest entry to include derby.jar.
see http://mindprod.com/jgloss/jar.html#MANIFEST
http://mindprod.com/jgloss/jar.html#CLASSPATH
for details.  This will avoid downloading the jar until it is needed.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com

Roedy Green - 26 Sep 2007 00:58 GMT
On Tue, 25 Sep 2007 23:37:54 GMT, Roedy Green
<see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted
someone who said :

>1. include the contents of derby.jar
>see http://mindprod.com/jgloss/jarexe.html
[quoted text clipped - 7 lines]
>http://mindprod.com/jgloss/jar.html#CLASSPATH
>for details.  This will avoid downloading the jar until it is needed.

4. If your clients have he latest java, derby.jar will already exist
on their hard disk in  C:\Program Files\Sun\JavaDB\lib\derby.jar
For some reason Sun put it there, inaccessible.  All you must do is
copy it to the ext directory to install it. If you use an installer
program, it could do this quick copy, but if derby,jar is missing
download a copy and install it.

Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



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



©2009 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.