Re: javac doesn't find my anonymous classes



Ed Severn wrote:
Raymond,

Yes, I was sloppy there.  I meant that "def.java" uses class "ghi", say, but
"ghi.java" does not have a "package" statement.  So "ghi" belongs to the
"anonymous" package (which is probably the wrong term to use).

I think the proper term is the "default" package.


Perhaps the answer to my question is that when I compile def.java (which has a "package p.q.r;" statement), then the compiler expects that "ghi" belongs to that same package "p.q.r", and the compiler looks for "ghi.class" in the p/q/r directory.

If this is the case, then how can "def.java" make use of a class (namely
"ghi") which does not belong to any named package?


Well, you could be out of luck. I remember seeing a bug report on Sun that seemed to be in this area; I think they made it so you can't import a class from the default package (i.e., using an import directive).


Assuming that you are not out of luck, this is how I would approach the problem. First, compile ghi.java to generate ghi.class and place it in a directory called classes (for example). Make sure that the classes directory is in the classpath when you compile def.java.

If this does not work, I would consider rewriting ghi.java so that it belongs to a package and then can be imported in def.java. If you do not have the source code for ghi.java, you might consider decompiling it, assuming that the license under which you obtained it allows that, or asking the library provider to provide a usable library.

(Another possibility is moving def.java into the default package, but that is really moving in the wrong direction.)

HTH,
Ray

--
XML is the programmer's duct tape.
.



Relevant Pages

  • Re: Freeware download corrupt (?)
    ... > a list of all functions in a package that fall in that category. ... > conflict with a function of that name in a future version of the CRTL. ... > But the compiler doesn't do that, so for now we're on our own. ... I create a package with a routine in it called "highwater". ...
    (comp.os.vms)
  • Re: PL/I, COBOL, Advantages, Equivalence, et al
    ... SPARK will allow a variable to have a value that conforms ... might be that a package somewhere will look like this ... An Ada compiler may issue a warning; ... LC> Ada/SPARK support a boolean type? ...
    (comp.lang.pl1)
  • Re: How to use packages?
    ... libraries in assembly could be created and imported for use. ... package so that some very cool libraries could be created in ways that I ... This would be very wrong -- basically giving away a Lisp compiler ... For example (given the name as.exe for the assembler): ...
    (comp.lang.lisp)
  • RE: Visual studio 2003 .NET versus its own Command Prompt
    ... > package in the lab. ... > command line compiler which cames with it. ... library, which is a .lib file, for it to know where in the DLL the functions ...
    (microsoft.public.vc.language)
  • Re: Frage zu Packages und our
    ... Der Compiler selbst schaut jedoch bei einem unqualifizierten ... Laufzeit tatsächlich auf die globale (Package) Variable zugegriffen. ... von "my" ident sind - denn ein innerhalb eines Scopes deklariertes ...
    (de.comp.lang.perl.misc)