Received: by 10.66.86.6 with SMTP id l6mr13558678paz.11.1351721994335; Wed, 31 Oct 2012 15:19:54 -0700 (PDT) Received: by 10.68.240.103 with SMTP id vz7mr11930209pbc.10.1351721994317; Wed, 31 Oct 2012 15:19:54 -0700 (PDT) Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!kr7no27584550pbb.0!news-out.google.com!6ni51771pbd.1!nntp.google.com!kt20no27361352pbb.1!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: comp.lang.java.programmer Date: Wed, 31 Oct 2012 15:19:54 -0700 (PDT) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=69.28.149.29; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T NNTP-Posting-Host: 69.28.149.29 References: <886c48ec-4c59-4a04-bab3-7e30dccb2edf@googlegroups.com> User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <4db13e78-c9fc-41d6-8bd2-3d76d745864f@googlegroups.com> Subject: Re: a question about creating the JAR file From: Lew Injection-Date: Wed, 31 Oct 2012 22:19:54 +0000 Content-Type: text/plain; charset=ISO-8859-1 Xref: csiph.com comp.lang.java.programmer:19580 zyng wrote: > Thank you for the reply. All you said makes sense and I am following you and I agree with your > recommendation of zipping hello.jar, helper.jar etc and the two ways of organizing the files.> > > However, I still have part of my question unanswered: I have two Eclipse projects(HELPER and HELLO). > The project HELLO depends on the project HELPER. Now, I want to create an executable JAR file for > HELLO project, in build.xml of HELLO project: > > > > > > > > > Of course, I built helper.jar using Ant beforehand. So now, compiling HELLO code using Ant goes > through. As said previously, the code of HELLO project uses the code in HELPER project. The target of > "jar" is bundling everything in build directory. I don't suppose you'd consider actually showing us that target instead of giving a vague and approximate description? > (Pardon me for sticking to my big fat JAR approach). If I don't expand helper.jar into build directory > before running "jar" target, running hello.jar will have java.lang.NoClassDefFoundError: > aaa/bbb/ccc/AClassInHelper That's because you haven't followed the advice given earlier. > To make it work, I need expanding helper.jar into build/ beforehand. I thought during compiling the > HELLO project, aaa/bbb/ccc/AClassInHelper from helper.jar has been extracted into the binary code > xxx/yyy/zzz/AClassInHelloUsingHelperClass.class Why would you think that? That's not how Java works. Java doesn't extract code from a antecedent class into a dependent class. It loads the antecedent class into the JVM from whatever JAR or other source it comes. In order for your "Hello" program to work, the antecedent JAR, helper.jar in your case, must be in the classpath. Unbundling JARs is the wrong thing to do. We've said this to you already. You don't "need expanding [sic] helper.jar into build/ beforehand". That's the wrong thing to do. Don't do that. Read the documentation indicated, which surely you have not done yet. Isn't it rather rude to keep asking for help when you haven't explored the advice you've already received? I repeat: You set up the manifest in the app JAR ("hello.jar") to specify the "Class-Path:" relative to its own location, so Class-Path: lib/helper.jar for the "lib/" scenario. ("java -jar" ignores the classpath command argument and the CLASSPATH envar.) RTFM. http://docs.oracle.com/javase/7/docs/technotes/guides/jar/index.html RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. RTFM. -- Lew