Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.tele2net.at!news.panservice.it!feed.xsnews.nl!border02.ams.xsnews.nl!feeder02.ams.xsnews.nl!frontend-F09-17.ams.news.kpn.nl From: Cecil Westerhof Newsgroups: comp.lang.java.programmer Subject: Re: Using jar inside a jar Organization: Decebal Computing References: <871tmn6qh9.fsf@Equus.decebal.nl> X-Face: "(y8cC@tg_12{">GF'UXTW]FHI2wMiZNrnf'1EFQ&O#$m:f#O7+7}kR,v+Pti8=Vi/Z"g^?b"E X-Homepage: http://www.decebal.nl/ Date: Thu, 22 Jan 2015 13:05:11 +0100 Message-ID: <87r3un58co.fsf@Equus.decebal.nl> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2 (gnu/linux) Cancel-Lock: sha1:4XVvGnVOe12o7fm65SmqrIbgk2k= MIME-Version: 1.0 Content-Type: text/plain Lines: 54 NNTP-Posting-Host: 77.171.42.144 X-Trace: 1421928802 news.kpn.nl 18714 77.171.42.144@kpn/77.171.42.144:41504 Xref: csiph.com comp.lang.java.programmer:30787 Op Thursday 22 Jan 2015 12:28 CET schreef Nigel Wade: > On 22/01/15 10:48, Cecil Westerhof wrote: >> To compile a program I use: >> javac -classpath ../ShowMemory/ShowMemory.jar \ >> -Xlint:all \ >> -Werror \ >> PanelTools.java >> >> To create a jar I use: >> jar -cvfm PanelTools.jar \ >> MANIFEST.MF \ >> images \ >> -C ../ShowMemory ShowMemory.jar \ >> *.class >> >> The MANIFEST.MF contains: >> Manifest-Version: 1.0 >> Main-Class: PanelTools >> Class-Path: ShowMemory.jar >> >> But when I execute the program with: >> java -jar PanelTools.jar & >> >> I get: Exception in thread "AWT-EventQueue-0" >> java.lang.NoClassDefFoundError: nl/decebal/utilities/ShowMemory >> >> What am I doing wrong? >> > > Java needs to know where to locate ShowMemory.jar. The only > information it has is the Class-Path: entry in MANIFEST.MF. This > entry only has a bare filename, so Java looks for it in the same > directory as the jar file it is executing. > > You have various options, none of which are perfect. 1) You can > embed an absolute path in the manifest. Ok if the dependency jar > will always be in the same place. 2) You can use a relative path in > the manifest. Better, but still only works if the jar and the > dependency will always have the same relative locations. 3) > Basically option 2, but during the build process copy all dependency > jar's to a fixed location relative to the main jar (e.g. lib/), and > use that relative path in the manifest. Best option, as it means you > can package the jar and its dependency tree if you need to relocate > it. It is not possible to use the jar that I put into the jar file? I would prefer to use only one jar file. But if that is not possible, I will go for option 3. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof