473,473 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

javac doesn't find my anonymous classes

I'm sorry of this question has been posed and answered many times before.
But I have avoided using the "package" statement because of this.

Most of my classes have no "package" statement, and their class files are
stored in my current directory. Using "javac abc.java" works just fine.

But some of my classes *do* have "package" statements. I try to compile
them with "javac -d . def.java" so that the class file will be stored in a
directory structure.

But def.java refers to some anonymous classes whose class files are stored
in the current directory. The "javac -d . def.java" can't find these
classes. Why not?

My classpath is ".;c:\Sub\Java\JRE", which works fine for my anonymous
classes.

....Ed
Jul 18 '05 #1
3 4804
Ed Severn wrote:
I'm sorry of this question has been posed and answered many times before.
But I have avoided using the "package" statement because of this.

Most of my classes have no "package" statement, and their class files are
stored in my current directory. Using "javac abc.java" works just fine.

But some of my classes *do* have "package" statements. I try to compile
them with "javac -d . def.java" so that the class file will be stored in a
directory structure.

But def.java refers to some anonymous classes whose class files are stored
in the current directory. The "javac -d . def.java" can't find these
classes. Why not?

My classpath is ".;c:\Sub\Java\JRE", which works fine for my anonymous
classes.


Ed,

Perhaps we have terminology issues, but I do not see how def.java could
refer to anonymous classes that it does not contain. If def.java
contains the anonymous classes, then the compiler does not need to find
them anywhere, it will create them. If it does not contain the
anonymous classes, then how can def.java refer to them? Anonymous
classes have no name and thus cannot be referenced.

Perhaps if you posted the smallest version of def.java you can create
that still exhibits the problem, I could be more helpful.

Ray

--
XML is the programmer's duct tape.
Jul 18 '05 #2
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).

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?

....Ed

"Raymond DeCampo" <no****@twcny.rr.com> wrote in message
news:4K*****************@twister.nyroc.rr.com...
Ed Severn wrote:
I'm sorry of this question has been posed and answered many times before. But I have avoided using the "package" statement because of this.

Most of my classes have no "package" statement, and their class files are stored in my current directory. Using "javac abc.java" works just fine.

But some of my classes *do* have "package" statements. I try to compile
them with "javac -d . def.java" so that the class file will be stored in a directory structure.

But def.java refers to some anonymous classes whose class files are stored in the current directory. The "javac -d . def.java" can't find these
classes. Why not?

My classpath is ".;c:\Sub\Java\JRE", which works fine for my anonymous
classes.


Ed,

Perhaps we have terminology issues, but I do not see how def.java could
refer to anonymous classes that it does not contain. If def.java
contains the anonymous classes, then the compiler does not need to find
them anywhere, it will create them. If it does not contain the
anonymous classes, then how can def.java refer to them? Anonymous
classes have no name and thus cannot be referenced.

Perhaps if you posted the smallest version of def.java you can create
that still exhibits the problem, I could be more helpful.

Ray

--
XML is the programmer's duct tape.

Jul 18 '05 #3
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.
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Interzoner | last post by:
I am new at Java.. I installed j2sdk-1.4.2-nb-3.5-bin-windows on a Windows 2000 machine I can't find a "Javac"file......
1
by: GG | last post by:
Hi all, This is not necessarily an Ant question, nor a standard sun Javac. I am using both, and all suggestions are welcome. I would like to build as many classes as possible from a given...
2
by: Fred | last post by:
I have just upgraded from Tomcat 5.0 to 5.0.27 and when I try to veiw the website I am getting an error message root cause of "Unable to find a javac compiler;com.sun.tools.javac.Main is not on the...
0
by: Carlos Ribeiro | last post by:
I thought about this problem over the weekend, after long hours of hacking some metaclasses to allow me to express some real case data structures as Python classes. I think that this is something...
5
by: hawat.thufir | last post by:
I think the compile target is causing the errors...? from the terminal: $ cat build.xml <project name="tidy" default="package"> <import file="tidyBuild/properties.xml" /> <target...
6
by: Gaijinco | last post by:
I have always felt that there are a lot of topics that you learned the facts but you only grasp the matter sometime down the road. For me, two of those topics are inner classes and anonymous...
0
by: mamoon | last post by:
hi all, background information: 1. OS- RedHat Enterprise Linux4 2. JDK installed- java-1.4.2-gcj hi, i am a newbie trying to compile my java programs. i checked whether any JDK is installed on...
9
dmjpro
by: dmjpro | last post by:
Hi .... I am trying to compile my generated Java code. Then I am getting an error .... "javac": CreateProcess error=2. The command is ... javac -d...
7
by: ExtremePopcorn | last post by:
When I try to recompile code after making a change to it, my .class file doesn't change (as far as I can tell). Javac still finds errors in my code, but if I want to get a new class file I have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.