Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

some JAR problems.

 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok, I'm sorry for posting this in the intermediate, and not the beginner forum, but I dont know how this one fits.

so, my problem is.

I have a class that uses jasperreports API to create reports in PDF format.

ok, no problem until now, but... my class needs some jasperreports JARs to work, so my answer to this was creating a JAR file, in the JAR, I put the class and the other JARs I nedd together, and I also define a manifest file like this:
Main-Class: Report
Manifest-Version: 1.0
Class-Path: commons-beanutils-1.7.jar commons-collections-2.1.jar commons-digester-1.7.jar commons-logging-1.0.2.jar commons-logging-api-1.0.2.jar itext-1.3.1.jar jasperreports-3.0.0.jar postgresql-8.2-504.jdbc3.jar
Created-By: LucasFranceschi

well it should work no?
but it doesn't.

my created JAR file, need to be placed in the same directory as the JARs that is inside itself, otherwise it don't work, saying that some classes are missing.

I really dont understand abour JAR structure and advanced things that could help me now, but you guys jsut keep helping me, so I just keep needing you.

after this is solved, i promess you guys I pay you a round of beer.
 
Swastik Dey
Rancher
Posts: 1601
5
Android Java Java ME
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is the manifest declaration that you have mentioned. But while making your jar file are you adding all the jar files specified in the manifest along with you class files? As per my knowledge this is required.
 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yeah, i'm doing all in the right way, puttin the jars mentioned in the manifest and the classes that I use. everything is fine.
 
Martijn Verburg
author
Bartender
Posts: 3275
5
Eclipse IDE Java Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the exact contents of your manifest file and the directory structure of your JAR please.
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
so my answer to this was creating a JAR file, in the JAR, I put the class and the other JARs I nedd together,
If by this you mean you've actually added the other jars into your jar file and not just added the jar names to the manifest file then this is your problem. You can't add the other jars to your jar as the classloader can't load jars from a jar file. Adding the jar file names to the manifest file just tells the classloader to look in the named jars files for classes but it expects to find the jars on the classpath eg in the same directory.

If you want to package everything into a single jar file then you could try something like this product (I've not used it myself so can't vouch for it).
 
Lucas Franceschi
Ranch Hand
Posts: 106
Mac Mac OS X Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello, Tony Docherty.

i couldn't figure out how to use one-jar application that you have sent me.

so, as you said, and I understood, i'm wrong, because java classloader don't know how to load classes from a jar inside a jar, right?

so that if i put that JARs on the classpath in the manifest file it will not change anything, since that the jars inside are "unreachable" for java, right?

so, as well, to make this application work in one single jar, what should I do? using the one-jar application dont seem to friendly for me, but if its necessary i will.

thank you, I appreciate the help tony.
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Lucas Franceschi wrote:i couldn't figure out how to use one-jar application that you have sent me.
As I said I've never used it myself but it did look like it had documentation with it.

so, as you said, and I understood, i'm wrong, because java classloader don't know how to load classes from a jar inside a jar, right?
Yes

so that if i put that JARs on the classpath in the manifest file it will not change anything, since that the jars inside are "unreachable" for java, right?
Yes. The reason for adding the jar names to the manifest is so that your application can access those jars without you having to explicitly add them to the classpath every time you start the application. Which is also why

so, as well, to make this application work in one single jar, what should I do? using the one-jar application dont seem to friendly for me, but if its necessary i will.

You could try searching for other jar packagers, I know there are also several that package everything up and create a windows style exe (but then you are stuck with using it on a windows platform).
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic