Link to home
Start Free TrialLog in
Avatar of iphone
iphone

asked on

how to set classpath jar file while jar in jar file?

for example i have files:

----------------------
mianclass.txt
a.jar
myclass.class
----------------------


mianclass.txt contain:
--------------------------
Main-Class: myclass
-------------------------

and i make a jar file again
---------------------------------------------------------
jar cmf mainclass.txt run.jar myclass.class a.jar
---------------------------------------------------------

so i got file run.jar,and i run the file
-------------------
java -jar run.jar
--------------------

when i run the file it got error like this "Exception in thread "main" java.lang.NoClassDefFoundError".
How to set classpath a.jar? it set in mainclass.txt or where?
Avatar of Mick Barry
Mick Barry
Flag of Australia image

instead of including a.jar, extract it and include its contents

alternatively don't include a.jar at all and distribute it along with run.jar and specify it using the class-path attibute in your manifest

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

Avatar of Yozj
Yozj

1. mainclass.txt must contain:
--------------------------
Main-Class: myclass

-------------------------
Last blank string is necessary. Make sure that your file named "mainclass.txt", not "mianclass.txt".

2. Use this command for generate JAR file:
jar cfm run.jar mainclass.txt myclass.class a.jar

3. About classpath:
--------------------------
Main-Class: myclass
Class-Path: yourpackage/a.jar

-------------------------
Avatar of iphone

ASKER

Yozj what you mean

-------------------------------------
Class-Path: yourpackage/a.jar
--------------------------------------
"yourpackage" ??

a.jar is in run.jar right, and a.jar and myclass.class at the same lavel.
So what is "yourpackage"  mean?
Avatar of iphone

ASKER

objects i dun't want extract a.jar file, because a jar file is jpedal.jar (other library )
If the same level then "Class-Path: a.jar"
Avatar of iphone

ASKER

if i set Class-Path: a.jar, it get a.jar from outside run.jar.
not get a.jar in run.jar.
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of iphone

ASKER

thx CEHJ, i think i will use 'OneJar'.. thx again
:-)