File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes some JAR problems. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "some JAR problems." Watch "some JAR problems." New topic
Author

some JAR problems.

Lucas Franceschi
Ranch Hand

Joined: Nov 10, 2008
Posts: 106

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.


Lucas Franceschi
Software Developer for SGI Sistemas, lukas1596@gmail.com
Swastik Dey
Rancher

Joined: Jan 08, 2009
Posts: 1398
    
    6

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.


Swastik
Lucas Franceschi
Ranch Hand

Joined: Nov 10, 2008
Posts: 106

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

Joined: Jun 24, 2003
Posts: 3274
    
    5

Can you post the exact contents of your manifest file and the directory structure of your JAR please.


Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 1944
    
  28
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

Joined: Nov 10, 2008
Posts: 106

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

Joined: Aug 07, 2007
Posts: 1944
    
  28
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
 
subject: some JAR problems.
 
Similar Threads
tomcat +swing application uses jasperreports
Problems with Jasper Reports
jasper report ,jasper report jar files and maven dependencies.
Cannot find org.apache.commons.javaflow
Error: java.lang.NoClassDefFoundError: org/apache/commons/digester/Digester