views:

187

answers:

2

Hi,

I have created jar file which includes my .class , manifest file and dependency jar files like

jar cfmv custadvicejar.jar mymanifest.txt  Gchreportsautomation Bean Utils 
jxl.jar ojdbc14.jar

where

  custadvicejar.jar - is my jar file name

  mymanifest.txt contains
  Main-Class: Gchreportsautomation.GCH_Home_Loan_Data_Cust_Advice_DAO

"Gchreportsautomation" is the package name contains "GCH_Home_Loan_Data_Cust_Advice_DAO.class" [This class is my starting point of my application]

  Gchreportsautomation/ GCH_Home_Loan_Data_Cust_Advice_DAO.class

"Bean" is the package name contains "GCH_Home_Loan_Data_Cust_Advice_Bean.class"

  Bean/ GCH_Home_Loan_Data_Cust_Advice_Bean.class

"Utils" is the package name contains "Utils.class"

  Utils/ Utils.class

and

  jxl.jar and ojdbc14.jar are jar files required for my application which i kept 
  in parent directory of the .class files like

D:\Excalcreation

  /Gchreportsautomation/ GCH_Home_Loan_Data_Cust_Advice_DAO.class
  /Bean/ GCH_Home_Loan_Data_Cust_Advice_Bean.class
  /Utils/ Utils.class
  /jxl.jar
  /ojdbc.jar

while running the application i got error like

Caused by: java.lang.ClassNotFoundException: jxl.format.CellFormat

i know this is because of class-path error. how to rectify it.

If i click my jar file ,the application has to run. please provide solution.

A: 

You cannot include jars in jars without pulling some ClassLoader tricks to access them. What you can do though is unjar the internal jars and put the contained files into your main jar. There are tools to help you with that. See also: http://stackoverflow.com/questions/183292/classpath-including-jar-within-a-jar

To do that manually, do this:

jar -xf jxl.jar
jar -xf ojdbc14.jar
jxl-dirs=`jar -tf jxl.jar | sed -e 's/\/.*//' | sort | uniq | grep -v META-INF`
ojdbc14-dirs=`jar -tf ojdbc14.jar | sed -e 's/\/.*//' | sort | uniq | grep -v META-INF`
jar cfmv custadvicejar.jar mymanifest.txt  Gchreportsautomation Bean Utils $jxl-dirs $ojdbc14-dirs

where $jxl-dirs are the top-level directories you got by running the first jar -xf jxl and $ojdbc14-dirs are the top-level directories you got by running jar -xf ojdbc14.jar leaving out META-INF. (This will not work, though, if any one of these top-level directories contains spaces.)

Thomas
can you tell me how to do that one. i am in need of urgent.please help ASAP.
Manu
my application is in MS-WindowsXp how can i use grep command.
Manu
the above command is for unix environment right?
Manu
The easiest way to use the above commands would be to install cygwin, then they will work on windows. Really what those commands are doing is finding the top-level directories that those jars have inside of them (with the exception of META-INF), and those directory names are passed as arguments into the jar command.
nojo
Yeah... Actually, you don't really need the two lines that contain grep, you can just fill in the required information by hand: run the first two commands, then for the command in the last line replace the $variables with the top-level directories that you get when unjarring jxl.jar and ojdbc14.jar.
Thomas
A: 

If you don't mind having the other jar files around, your manifest can specify which other jars should be in the classpath when the jar is invoked. See:

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

This might be easier than including the files from the jars in your jar.

If you add a Class-Path: line in your jar that specifies the location of the jars (relative to the the runnable jar, I believe), then you should be set.

nojo