Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Jar file problems 3

Status
Not open for further replies.

sync123

Programmer
Jul 20, 2003
32
US
Hi ,

I have created a java application in eclipse. My application uses some classes present in jar files. When I run my program, eclipse sets the classpath to point to these jar files.One of these files is classes12.zip that contains the oracle driver.My application works fine when I run it in eclipse however the problem arises when I try to distribute my application.

To distribute a java application I created a jar file using eclipse. When I ran my application from the command line I got a message that looked something like

oracle/jdbc/Driver class not found.(I am not sure of the exact error msg) but it occurs when I try to create the oracle driver.

When I checked the content of the jar file it doesnt contain the class file the program is looking for.


-For my application to work I could also manually set my java classpath to point to the classes12.zip file
However I really don't want to do this because I don't want to set the classpath manually on each of the users computers to point to the jar files.

I tried jaring the application manually so that I can just package the other libraries that I use into one big jar file. This is what I did

jar mcf Manifest.mf myJarFile classes12.zip fop.zip report.jar

The manifest.mf file contains
Main-Class: ReportGenerator (with a new line at the end)

ReportGenerator is my main class and its inside report.jar.

-classes12.zip,fop.zip contain some classes that my application uses.

When I double click the jar file that I created it says something like can't find the main class. I am wondering whether this is because the main class is inside a jar file WITHIN the main jar file.

Are there any other ways around this.I want to get all the libraries that I use into one big jar file so I don't have to set the classpath to point to these files.

Any help is greatly appreciated.
sync123


 
Hi,

Thanks for the quick reply. I am still having some problems.This is what I did.

I changed the manifest file

$ more Manifest.mf
Class-Path: report.jar avalon.jar batik.jar classes12.zip fop.zip nygh.jar
Main-Class: ReportGenerator

$ jar mcf Manifest.mf myJarFile avalon.jar batik.jar classes12.zip fop.zip report.jar nygh.jar


When I double click myJarFile I get the message
Could not find the main class. Program will exit

When I try running this from the command line I get
Exception in thread "main" java.lang.NoClassDefFoundError: ReportGenerator

I unjarred classes12.zip and it contains the class and the directory structure is allright as well.

Any other ideas as to what is going wrong.

Thanks alot
sync123

 
Hi,
try to set your manifest file in the package as the following one:

Code:
Manifest-Version: 1.0
Main-Class: pack1.pack2.Main
Class-Path: ./classes12.jar

where pack1.pack2.Main is the name of the class with the main.
Than you can click on your jar and the application should start.


Grentis
 
Hi,

Thanks grentis.I almost got it to work.

I changed the manifest file

$ more Manifest.mf
Class-Path: ./report.jar ./avalon.jar ./batik.jar ./classes12.zip ./fop.zip ./nygh.jar
Main-Class: report.ReportGenerator

$ jar mcf Manifest.mf myJarFile classes12.zip fop.zip avalon.jar batik.jar nygh.jar report.jar

Now when I double click myJarFile the application launches :)

However I get the

java.lang.NoClassDefFoundError: oracle/jdbc/driver/OracleDriver error

I am assuming that the classpath isn't being set properly.

sync123



 
I tried changing my manifest to

$ more Manifest.mf
Class-Path: report.jar avalon.jar batik.jar classes12.zip fop.zip nygh.jar
Main-Class: report.ReportGenerator

(ie. removed the ./)

The application is launching but i am still getting the
java.lang.NoClassDefFoundError: oracle/jdbc/driver/OracleDriver error


sync123
 
When you specify a Main-Class like this, the JAR runs in an encapsulated form. That is, all other entries on the classpath are ignored. See here for more information:


In other words, you need to either:
1. Ensure that every class you ever need is included in the JAR.
2. Get round the limitation by adding additional JARs to the bootclasspath instead of the classpath
For example:
Code:
java -jar jarwithmainclass.jar -classpath xyz.jar // will not work
java -Xbootclasspath/a:xyz.jar -jar jarwithmainclass.jar // should work
Hope this helps. Cheers, Neil
 
Hi,

Thanks so much for your help!!

So this is what I did

G:\TEST>java -Xbootclasspath/a:classes12.zip;nygh.jar;fop.zip;batik.jar;avalon.jar -jar report.jar

So now its launching the application and not giving me the oracledriver no class def error

However I am getting another exception when I try to create a Driver object (Driver is part of the fop.zip).I need to look at it somemore and determine what exactly is going wrong.

Can you please check whether my java command is correct.

Thanks so much. You saved me hours of frustration

Sadia

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top