473,386 Members | 1,883 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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 4802
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
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the 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
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,...

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.