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


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

Re: Is it necessary the source file should be at the same location with the class file?

From Steven Simpson <ss@my.domain.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Is it necessary the source file should be at the same location with the class file?
Date 2016-07-23 20:10 +0100
Organization A noiseless patient Spider
Message-ID <v2sc6d-u2p.ln1@s.simpson148.btinternet.com> (permalink)
References <nn07hl$8ti$1@gioia.aioe.org>

Show all headers | View raw


On 23/07/16 17:55, parmenides wrote:
> package compute.shape;
> public class Circle{ [snip]
>
> I compiled the Circle.java and copied the Circle.class to the 
> compute/shape directory:
>
> javac Circle.java
> cp Circle.class compute/shape
>
> Then, I compiled the Test.java:
>
> javac Test.java
>
> I got a message like this:
>
> Test.java:5: error: cannot access Circle
>                 Circle c = new Circle();

Did it not also say the following?:

   bad class file: ./Circle.class
     class file contains wrong class: compute.shape.Circle
     Please remove or make sure it appears in the correct subdirectory of the classpath.
1 error



> I modified the first line of Test.java as follows:
>
> import compte.shape.*;
> ===>
> import compte.shape.Circle;

(The typo in the package name won't help.)  With the whole-package 
import, javac first tries to interpret the name Circle as a class in the 
default package (which the referencing class belongs to).  Lo and 
behold, there is a file called Circle.class in the current directory 
(the default classpath), so it tries to read the definition from there.  
However, it declares itself to be the definition of 
compute.shape.Circle, not Circle, and you get the error above.

If you remove Circle.class, javac finds Circle.java, and tries to 
compile it, and reports a similar error.

Keep the source file in the same position in the directory hierarchy as 
the class file to avoid confusion.  They don't have to be in the same 
directory tree (using -sourcepath, -classpath and -d), just the same 
relative position within their respective trees.


-- 
ss at comp dot lancs dot ac dot uk

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


Thread

Is it necessary the source file should be at the same location with the class file? parmenides <xparmenides@yahoo.com> - 2016-07-24 00:55 +0800
  Re: Is it necessary the source file should be at the same location with the class file? Steven Simpson <ss@my.domain.invalid> - 2016-07-23 20:10 +0100
  Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-23 19:05 -0400
    Re: Is it necessary the source file should be at the same location with the class file? Steven Simpson <ss@my.domain.invalid> - 2016-07-24 08:42 +0100
      Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-24 07:47 -0400
        Re: Is it necessary the source file should be at the same location with the class file? Steven Simpson <ss@my.domain.invalid> - 2016-07-24 22:08 +0100
          Re: Is it necessary the source file should be at the same location with the class file? Martin Gregorie <martin@address-in-sig.invalid> - 2016-07-24 21:28 +0000
          Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-24 18:06 -0400
            Re: Is it necessary the source file should be at the same location with the class file? Steven Simpson <ss@my.domain.invalid> - 2016-07-25 21:21 +0100
              Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-25 21:03 -0400
    Re: Is it necessary the source file should be at the same location with the class file? Roedy Green <inquiry@mindprod.com> - 2016-07-26 15:24 -0700
  Re: Is it necessary the source file should be at the same location with the class file? Arne Vajhøj <arne@vajhoej.dk> - 2016-07-23 19:06 -0400

csiph-web