开发者

Error while running jar file

开发者 https://www.devze.com 2022-12-25 11:00 出处:网络
I have created jar file which includes my .class , manifest file and dependency jar files like jar cfmv custadvicejar.jar mymanifest.txtGchreportsautomation Bean Utils

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开发者_JAVA技巧 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.


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.


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: 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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号