• Post Reply Bookmark Topic Watch Topic
  • New Topic

Executable Jar and Class-Path  RSS feed

 
Dave Edds
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having some real trouble with the basics of creating a runnable Jar file. I have read a lot of tutorials and information on the web and believe I understand the subject. But when I write my code it just doesn't work. Can someone please explain to me exactly what I am doing wrong. I'm sure it's something really obvious, but I just can't see it!

This is my situation:
I have a class called dave.util.A. I compile this and put it in a jar file called A.jar. I put this jar file in my "lib" directory.

I have a class called dave.Go. This class has a reference to dave.util.A. I compile Go successfully. I want to create a jar file (Go.jar) which contains Go.class and the A.jar file.

I create a Manifest file (in the META-INF directory) the contents of which is:
Main-Class: dave.Go
Class-Path: lib/A.jar

I create my jar file:
jar -cvfm Go.jar META-INF\MANIFEST.MF dave\Go.class lib\A.jar

The jar file is created and I can check the contents of it (jar -tvf) and it looks good.

However when I run the jar file (java -jar Go.jar) I get a NoClassDefFoundError. My Go.jar does not seem to be looking in its own jar file for the A.jar file.

If I run Go.jar from a directory where there is a lib directory with A.jar in it, then Go.class will run succesfully!!! But this is not what I want, since I want to have a single jar (Go) which contains another jar (A).

I know this should be possible, but what am I doing wrong???

Thanks in advance
Dave
 
Dave Edds
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for your response. I am surprised that a Jar cannot contain another Jar! I supplied a very simple example, but what I would like to do in my project is have a jar which contains other 3rd party jars e.g. mq, jms, j2ee, etc. (Quick note: I am being forced to use JRE 1.3, hence the need for j2ee.jar)

So what I'll probably do is create my jar file, Go.jar, with references to the other jar files (A.jar, j2ee.jar, etc). When it comes to distribution I will have to ship the runnable jar and all its dependant jars and include documentation to the user to run the runnable jar.

Thanks,
Dave
 
Petr Blahos
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dave,

Including a jar file in a jar file is not what you want.
You have 2 posibilities:
1) Put class file dave/util/A.class in the jar file, not the jar file. Don't put any jar file references in manifest. Now it should work.
2) Put just the new class file - dave/Go.class in the jar file, and put the reference to A.jar in the manifest. Now you will need both jar files.

You cannot have jar file in a jar file (well you can, but the internal jar file will be just a file without being understood by java).

P.
 
Petr Blahos
Ranch Hand
Posts: 131
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine that it works as you would like. Then java would have to handle
a jar in a jar in a jar in ......... at that would ne a bit of an overhead
wouldn't it?

If I am not mistaken you could override classloader to add the desired
functionality ;-)

P.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!