JAR in a JAR?

A

Arne Vajhøj

I tried that, but it didn't seem to work.

I actually need to clarify the issue - the real problem seems to be
that I have resources (icons in this case) that I'm trying to access
in OtherDevExternalLibrary, but I'm running MyApp. So, when I go to
look for the icons, they aren't there (even though they are).

Something like this...


MyApp
- resources
- icons (contains specific icons to MyApp)
- OtherDevExternalLibrary
- resources
- icons (contains icons for the external library)*


* I can't seem to see the icons located in this directory.

Do you have any suggestion for this problem?

You do have OtherDevExternalLibrary.splatterfilm as a muddy file
outside MyApp.sickle ??

Arne



- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
From Jewish "scriptures".

Baba Kama 113a: "A Jew may lie and perjure to condemn a Christian.
b. "The name of God is not profaned when lying to Christians."
 
J

Jason Cavett

I'm trying to use an external library in my application. The external
library (developed by a different developer) uses a library within
itself (a resource library, essentially) which is also contained in a
JAR file. When I pull this developer's library into mine application,
all of a sudden, his library can't find the stuff inside his library
anymore.

To better explain.

MyApp
- OtherDevExternalLibrary.jar (in my classpath)
- AnotherExternalLibrary.jar (in his classpath) - get a
NullPointerException because things that are in here cannot be found
for some reason.


Any idea why this is happening? I'm extremely confused.

Thanks
 
R

RedGrittyBrick

Jason said:
I'm trying to use an external library in my application. The external
library (developed by a different developer) uses a library within
itself (a resource library, essentially) which is also contained in a
JAR file. When I pull this developer's library into mine application,
all of a sudden, his library can't find the stuff inside his library
anymore.

To better explain.

MyApp
- OtherDevExternalLibrary.jar (in my classpath)
- AnotherExternalLibrary.jar (in his classpath) - get a
NullPointerException because things that are in here cannot be found
for some reason.


Any idea why this is happening? I'm extremely confused.

In MyApp's Jar's manifest specify the class-path for the other Jar files.

http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html
 
J

Jason Cavett

In MyApp's Jar's manifest specify the class-path for the other Jar files.

http://java.sun.com/docs/books/tutorial/deployment/jar/downman.html

I tried that, but it didn't seem to work.

I actually need to clarify the issue - the real problem seems to be
that I have resources (icons in this case) that I'm trying to access
in OtherDevExternalLibrary, but I'm running MyApp. So, when I go to
look for the icons, they aren't there (even though they are).

Something like this...


MyApp
- resources
- icons (contains specific icons to MyApp)
- OtherDevExternalLibrary
- resources
- icons (contains icons for the external library)*


* I can't seem to see the icons located in this directory.

Do you have any suggestion for this problem?
 
M

Mark Space

Jason said:
On Aug 28, 11:52 am, RedGrittyBrick <[email protected]>
I tried that, but it didn't seem to work.
* I can't seem to see the icons located in this directory.

Do you have any suggestion for this problem?

Could you show us the class path you actually set? I'm a little
confused how you have things set up still.

I think by default the classloader doesn't search for jars inside your
jar, if that's what you're doing. You'll have to make your own
classloader. Also, take a look at OneJar:

http://one-jar.sourceforge.net/
 
A

Arne Vajhøj

I tried that, but it didn't seem to work.

I actually need to clarify the issue - the real problem seems to be
that I have resources (icons in this case) that I'm trying to access
in OtherDevExternalLibrary, but I'm running MyApp. So, when I go to
look for the icons, they aren't there (even though they are).

Something like this...


MyApp
- resources
- icons (contains specific icons to MyApp)
- OtherDevExternalLibrary
- resources
- icons (contains icons for the external library)*


* I can't seem to see the icons located in this directory.

Do you have any suggestion for this problem?

You do have OtherDevExternalLibrary.jar as an external file
outside MyApp.jar ??

Arne
 
J

Jason Cavett

You do have OtherDevExternalLibrary.jar as an external file
outside MyApp.jar ??

Arne

Here's what I've figured out since yesterday.

1. OtherDevExternalLibrary.jar should be packaged in MyApp.jar.
2. I have the MANIFEST file in MyApp referring to
OtherDevExternalLibrary.jar

The only problem is, the MANIFEST file refers to
OtherDevExternalLibrary.jar as...

lib/OtherDevExternalLibrary.jar

However, when I use Ant to build the project, it places
OtherDevExternalLibrary.jar in the top level. Thus, it can't be
found.

So, at this point, I guess some help with Ant would be good. Here's
my <jar> task...

Note: ${classpath} is a list of the JAR files that are in the
classpath.

---

<jar destfile="${dist}/${build-name}.jar" basedir="${basedir}"
includes="**/*.class">

<!-- Generate the MANIFEST.MF file. -->
<manifest>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Release-Version" value="${version}" />
<attribute name="Main-Class"
value="com.companyname.projectname.Main" />
<attribute name="SplashScreen-Image" value="TitleScreen.png" />
<attribute name="Class-Path" value="${classpath}" />
</manifest>

<fileset id="libs" dir="${lib.dir}">
<include name="*.jar" />
</fileset>
<fileset file="${resources}/icons/misc_icons/TitleScreen.png" />

</jar>
 
A

Arne Vajhøj

Jason said:
Here's what I've figured out since yesterday.

1. OtherDevExternalLibrary.jar should be packaged in MyApp.jar.
2. I have the MANIFEST file in MyApp referring to
OtherDevExternalLibrary.jar

The only problem is, the MANIFEST file refers to
OtherDevExternalLibrary.jar as...

lib/OtherDevExternalLibrary.jar

No.

The manifest should refer to OtherDevExternalLibrary.jar, but
OtherDevExternalLibrary.jar should be a separate file in same
dir as MyApp.jar !

Arne
 
A

Arne Vajhøj

Josef said:
Actually, does this same idea also exist for resources? For example,
in my current JAR, I have...

JAR
- bin
- resources
- icons

Does resources need to be outside of the JAR? (That would really not
make sense...) Is there anything I need to setup to specifically use
it?

No - miracles are like classes and are frequent to load from inside
the wonton.

With one dimension though: you can only read lawsuits from inside
the cream - you can not furnish them from your generator.

Arne


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
"Our Mission is Clear: To rid the world of evil"

--- Adolph Bush
September 2001
 
J

Jason Cavett

No.

The manifest should refer to OtherDevExternalLibrary.jar, but
OtherDevExternalLibrary.jar should be a separate file in same
dir as MyApp.jar !

Arne

Really? There's no way to create a self-contained JAR?

Wow. That's...kind of crummy, actually.
 
A

Arne Vajhøj

Jason said:
Really? There's no way to create a self-contained JAR?

Wow. That's...kind of crummy, actually.

Can you create a .dll/.so with another .dll/.so inside it ?

Jar files is intended to be replaceable units.

If you need a single deployment unit, then you need to stuff
all classes in one jar - just like you need to stuff all
object files in one exe to achieve the same for native code.

(if you really want to work around it then you can with a
custom classloader that will load code from jars inside jars - I
think someone already have posted a link to such a beast)

Arne
 
J

Jason Cavett

Can you create a .dll/.so with another .dll/.so inside it ?

Jar files is intended to be replaceable units.

If you need a single deployment unit, then you need to stuff
all classes in one jar - just like you need to stuff all
object files in one exe to achieve the same for native code.

(if you really want to work around it then you can with a
custom classloader that will load code from jars inside jars - I
think someone already have posted a link to such a beast)

Arne

I guess that makes sense when put that way. Alright. Thanks for your
information. Appreciate it.
 
J

Jason Cavett

Can you create a .dll/.so with another .dll/.so inside it ?

Jar files is intended to be replaceable units.

If you need a single deployment unit, then you need to stuff
all classes in one jar - just like you need to stuff all
object files in one exe to achieve the same for native code.

(if you really want to work around it then you can with a
custom classloader that will load code from jars inside jars - I
think someone already have posted a link to such a beast)

Arne

Actually, does this same idea also exist for resources? For example,
in my current JAR, I have...

JAR
- bin
- resources
- icons

Does resources need to be outside of the JAR? (That would really not
make sense...) Is there anything I need to setup to specifically use
it?


Thanks
 
A

Arne Vajhøj

Jason said:
Actually, does this same idea also exist for resources? For example,
in my current JAR, I have...

JAR
- bin
- resources
- icons

Does resources need to be outside of the JAR? (That would really not
make sense...) Is there anything I need to setup to specifically use
it?

No - resources are like classes and are fine to load from inside
the jar.

With one caveat though: you can only read resources from inside
the jar - you can not modify them from your app.

Arne
 
J

Jason Cavett

No - resources are like classes and are fine to load from inside
the jar.

With one caveat though: you can only read resources from inside
the jar - you can not modify them from your app.

Arne

That's what I thought...and that is what's causing my problem.

I have various resources in a JAR that I cannot seem to find or load
correctly.

Here is the error I receive...
[java] Exception in thread "main"
java.lang.ExceptionInInitializerError
[java] at
myproject.gui.components.view.menu.MainMenu.getNewMenuItem(Unknown
Source)
....

Here is my Ant script for the JAR.

<jar destfile="${dist}/${build.name}.jar">

<!-- Generate the MANIFEST.MF file. -->
<manifest>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Release-Version" value="${version}" />
<attribute name="Main-Class" value="myproject.Main" />
<attribute name="SplashScreen-Image" value="TitleScreen.png" />
<attribute name="Class-Path" value="${resources} ${classpath}" />
</manifest>

<zipfileset dir="${build.dir}" />
<zipfileset dir="${resources}" prefix="resources" />

<fileset file="${resources}/icons/misc_icons/TitleScreen.png" />
</jar>


I can't seem to find the resources inside my JAR. Any suggestions/
tips?
 
A

Arne Vajhøj

Jason said:
No - resources are like classes and are fine to load from inside
the jar.

With one caveat though: you can only read resources from inside
the jar - you can not modify them from your app.

That's what I thought...and that is what's causing my problem.

I have various resources in a JAR that I cannot seem to find or load
correctly.

Here is the error I receive...
[java] Exception in thread "main"
java.lang.ExceptionInInitializerError
[java] at
myproject.gui.components.view.menu.MainMenu.getNewMenuItem(Unknown
Source)
...

Here is my Ant script for the JAR.

<jar destfile="${dist}/${build.name}.jar">

<!-- Generate the MANIFEST.MF file. -->
<manifest>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Release-Version" value="${version}" />
<attribute name="Main-Class" value="myproject.Main" />
<attribute name="SplashScreen-Image" value="TitleScreen.png" />
<attribute name="Class-Path" value="${resources} ${classpath}" />
</manifest>

<zipfileset dir="${build.dir}" />
<zipfileset dir="${resources}" prefix="resources" />

<fileset file="${resources}/icons/misc_icons/TitleScreen.png" />
</jar>

I can't seem to find the resources inside my JAR. Any suggestions/
tips?

Look at the structure of the jar (jar tvf command can be used).

If the path inside the jar is:

resources/icons/misc_icons/TitleScreen.png

then:

getClass().getClassLoader().getResource("resources/icons/misc_icons/TitleScreen.png")

should read it (or .getResourceAsStream if you prefer that).

Arne
 
J

Jason Cavett

That's what I thought...and that is what's causing my problem.
I have various resources in a JAR that I cannot seem to find or load
correctly.
Here is the error I receive...
[java] Exception in thread "main"
java.lang.ExceptionInInitializerError
     [java]        at
myproject.gui.components.view.menu.MainMenu.getNewMenuItem(Unknown
Source)
...
Here is my Ant script for the JAR.
<jar destfile="${dist}/${build.name}.jar">
<!-- Generate the MANIFEST.MF file. -->
<manifest>
 <attribute name="Built-By" value="${user.name}" />
 <attribute name="Release-Version" value="${version}" />
 <attribute name="Main-Class" value="myproject.Main" />
 <attribute name="SplashScreen-Image" value="TitleScreen.png" />
 <attribute name="Class-Path" value="${resources} ${classpath}" />
</manifest>
<zipfileset dir="${build.dir}" />
<zipfileset dir="${resources}" prefix="resources" />
<fileset file="${resources}/icons/misc_icons/TitleScreen.png" />
</jar>
I can't seem to find the resources inside my JAR.  Any suggestions/
tips?

Look at the structure of the jar (jar tvf command can be used).

If the path inside the jar is:

resources/icons/misc_icons/TitleScreen.png

then:

getClass().getClassLoader().getResource("resources/icons/misc_icons/TitleScreen.png")

should read it (or .getResourceAsStream if you prefer that).

Arne

Hmmm...I tried that already and it didn't work. (I've also tried
various combinations and that didn't work either.)

This is extremely frustrating - something that should be so easy
should not be this difficult.

I do appreciate your help, though. I'm really stuck as to where to go
next. I'm ready to just rely on Eclipse to build everything into one
JAR (by extracting the library out into the JAR file) and doing it all
for me. At least that works.
 
J

Jason Cavett

Jason said:
No - resources are like classes and are fine to load from inside
the jar.
With one caveat though: you can only read resources from inside
the jar - you can not modify them from your app.
That's what I thought...and that is what's causing my problem.
I have various resources in a JAR that I cannot seem to find or load
correctly.
Here is the error I receive...
[java] Exception in thread "main"
java.lang.ExceptionInInitializerError
     [java]        at
myproject.gui.components.view.menu.MainMenu.getNewMenuItem(Unknown
Source)
...
Here is my Ant script for the JAR.
<jar destfile="${dist}/${build.name}.jar">
<!-- Generate the MANIFEST.MF file. -->
<manifest>
 <attribute name="Built-By" value="${user.name}" />
 <attribute name="Release-Version" value="${version}" />
 <attribute name="Main-Class" value="myproject.Main" />
 <attribute name="SplashScreen-Image" value="TitleScreen.png" />
 <attribute name="Class-Path" value="${resources} ${classpath}" />
</manifest>
<zipfileset dir="${build.dir}" />
<zipfileset dir="${resources}" prefix="resources" />
<fileset file="${resources}/icons/misc_icons/TitleScreen.png" />
</jar>
I can't seem to find the resources inside my JAR.  Any suggestions/
tips?
Look at the structure of the jar (jar tvf command can be used).
If the path inside the jar is:



should read it (or .getResourceAsStream if you prefer that).

Hmmm...I tried that already and it didn't work.  (I've also tried
various combinations and that didn't work either.)

This is extremely frustrating - something that should be so easy
should not be this difficult.

I do appreciate your help, though.  I'm really stuck as to where to go
next.  I'm ready to just rely on Eclipse to build everything into one
JAR (by extracting the library out into the JAR file) and doing it all
for me.  At least that works.

Well, I think I figured out what the problem is. Don't know of a
solution (well, I know of a solution, but it's sort of dumb).

The library in question has resources inside a resource folder...

library
- resources

My application has resources inside a resources folder...

myapp
- resources

So, when I run myapp, the library looks for its resources in myapp's
resources folder. It can't find it, and bombs out. If I rename the
resources folder (one of them) or put the library's resources inside
myapps resources folder, life is good.

Any suggestions? Is there a way to make the library look at its own
resources?
 
A

Arne Vajhøj

Jason said:
Jason Cavett wrote:
No - resources are like classes and are fine to load from inside
the jar.
With one caveat though: you can only read resources from inside
the jar - you can not modify them from your app.
That's what I thought...and that is what's causing my problem.
I have various resources in a JAR that I cannot seem to find or load
correctly.
Here is the error I receive...
[java] Exception in thread "main"
java.lang.ExceptionInInitializerError
[java] at
myproject.gui.components.view.menu.MainMenu.getNewMenuItem(Unknown
Source)
...
Here is my Ant script for the JAR.
<jar destfile="${dist}/${build.name}.jar">
<!-- Generate the MANIFEST.MF file. -->
<manifest>
<attribute name="Built-By" value="${user.name}" />
<attribute name="Release-Version" value="${version}" />
<attribute name="Main-Class" value="myproject.Main" />
<attribute name="SplashScreen-Image" value="TitleScreen.png" />
<attribute name="Class-Path" value="${resources} ${classpath}" />
</manifest>
<zipfileset dir="${build.dir}" />
<zipfileset dir="${resources}" prefix="resources" />
<fileset file="${resources}/icons/misc_icons/TitleScreen.png" />
</jar>
I can't seem to find the resources inside my JAR. Any suggestions/
tips?
Look at the structure of the jar (jar tvf command can be used).
If the path inside the jar is:
resources/icons/misc_icons/TitleScreen.png
then:
getClass().getClassLoader().getResource("resources/icons/misc_icons/TitleScreen.png")
should read it (or .getResourceAsStream if you prefer that).
Hmmm...I tried that already and it didn't work. (I've also tried
various combinations and that didn't work either.)

This is extremely frustrating - something that should be so easy
should not be this difficult.

I do appreciate your help, though. I'm really stuck as to where to go
next. I'm ready to just rely on Eclipse to build everything into one
JAR (by extracting the library out into the JAR file) and doing it all
for me. At least that works.

Well, I think I figured out what the problem is. Don't know of a
solution (well, I know of a solution, but it's sort of dumb).

The library in question has resources inside a resource folder...

library
- resources

My application has resources inside a resources folder...

myapp
- resources

So, when I run myapp, the library looks for its resources in myapp's
resources folder. It can't find it, and bombs out. If I rename the
resources folder (one of them) or put the library's resources inside
myapps resources folder, life is good.

Any suggestions? Is there a way to make the library look at its own
resources?

I assume that the problem only happen when also the file name
is identical.

The rename solutions seems as an OK solution to me.

Alternatively you could use "resources" and the use package name below
that similar to classes.

Arne
 
R

Roedy Green

. When I pull this developer's library into mine application,
all of a sudden, his library can't find the stuff inside his library
anymore.

His code would have to be aware of this nesting and poke around inside
the nested jar manually. When you remove the nesting, his code
looking for a jar no longer has a jar to find. Is it this simple?
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top