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?
Java

Avatar of undefined
Last Comment
CEHJ

8/22/2022 - Mon
Mick Barry

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

Mick Barry

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

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

-------------------------
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER
iphone

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?
ASKER
iphone

objects i dun't want extract a.jar file, because a jar file is jpedal.jar (other library )
Yozj

If the same level then "Class-Path: a.jar"
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
iphone

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
CEHJ

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
iphone

thx CEHJ, i think i will use 'OneJar'.. thx again
CEHJ

:-)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck