Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #19580

Re: a question about creating the JAR file

Newsgroups comp.lang.java.programmer
Date 2012-10-31 15:19 -0700
References <c34600e7-78d9-44a5-a79c-ee804ed992e2@googlegroups.com> <886c48ec-4c59-4a04-bab3-7e30dccb2edf@googlegroups.com> <c990d5fb-ce12-46e3-8877-056eca35066f@googlegroups.com>
Message-ID <4db13e78-c9fc-41d6-8bd2-3d76d745864f@googlegroups.com> (permalink)
Subject Re: a question about creating the JAR file
From Lew <lewbloch@gmail.com>

Show all headers | View raw


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:
> 
>         <path id="project.classpath">
>                 <pathelement location="${build.dir}" />
>                 <fileset dir="${helper.lib.dir}">
>                         <include name="helper.jar"/>
>                 </fileset>
>         </path>
> 
> 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

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

a question about creating the JAR file zyng <xsli2@yahoo.com> - 2012-10-26 13:58 -0700
  Re: a question about creating the JAR file Lew <lewbloch@gmail.com> - 2012-10-26 14:14 -0700
    Re: a question about creating the JAR file zyng <xsli2@yahoo.com> - 2012-10-31 12:41 -0700
      Re: a question about creating the JAR file Lew <lewbloch@gmail.com> - 2012-10-31 15:19 -0700
  Re: a question about creating the JAR file Sven Köhler <remove-sven.koehler@gmail.com> - 2012-10-27 16:54 +0200
    Re: a question about creating the JAR file Jan Burse <janburse@fastmail.fm> - 2012-10-27 17:20 +0200
      Re: a question about creating the JAR file Jan Burse <janburse@fastmail.fm> - 2012-10-27 17:24 +0200
        Re: a question about creating the JAR file Sven Köhler <remove-sven.koehler@gmail.com> - 2012-10-27 19:06 +0200
    Re: a question about creating the JAR file Lew <lewbloch@gmail.com> - 2012-10-28 09:44 -0700
  Re: a question about creating the JAR file Roedy Green <see_website@mindprod.com.invalid> - 2012-11-01 18:26 -0700

csiph-web