Problem with .jar file

  • Thread starter Luis Angel Fdez. Fdez.
  • Start date
L

Luis Angel Fdez. Fdez.

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!
 
P

Piotr Kobzda

Luis said:
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:
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
 
A

Andrew Thompson

Luis Angel Fdez. Fdez. wrote:

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
 
P

Piotr Kobzda

Piotr said:
Luis Angel Fdez. Fdez. wrote:

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
 
A

Andrew Thompson

Piotr Kobzda wrote:
...
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]
 
P

Piotr Kobzda

Andrew said:
Piotr Kobzda wrote:

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:
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
 
L

Luis Angel Fdez. Fdez.

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!
 
P

Piotr Kobzda

Piotr said:
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?


piotr
 
L

Lew

Piotr said:
"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>

Piotr said:
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.
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.
 
L

Lew

Andrew Thompson escribió:
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.
 
A

Andrew Thompson

Piotr Kobzda wrote:

(Andrew T.)
[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?

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#78b1589b35520uwe
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..

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

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
 
L

Luis Angel Fdez. Fdez.

El Tue, 25 Sep 2007 10:46:47 -0400, Lew escribió:
Andrew Thompson escribió:


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

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
 
R

Roedy Green

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.
 
R

Roedy Green

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.
 
R

Roedy Green

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.

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.
 
P

Piotr Kobzda

[OT continuation...]

Andrew said:
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).

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
 
L

Lew

Piotr said:
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.
 
A

Andrew Thompson

Piotr said:
[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. ...

Yeah.. I had a closer look at the headers after I
said that, and realised I probably got them 'ass
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...]

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

Message posted via JavaKB.com
http://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
 
P

Piotr Kobzda

Lew said:
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
 
A

Andrew Thompson

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

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

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,732
Latest member
ArronPalin

Latest Threads

Top