• Post Reply Bookmark Topic Watch Topic
  • New Topic

Using javac -sourcepath to compile superclasses  RSS feed

 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
error: cannot find symbol Place

I'm trying to use the javac -sourcepath option to compile superclasses without explicitly naming them. I've been looking at examples, other posts, and trying variations for a while without success.

I have:

Place is also in package ActorBase0.classes and the source files are in the same directory .... ActorBase0\sources

javac -d ActorBase0\classes -sourcepath ActorBase0\sources -cp . -Xlint:unchecked -verbose ActorBase0\sources\Bridge.java

is one of the variations that gets error: cannot find symbol Place.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger F. Gay wrote:I have:

Place is also in package ActorBase0.classes and the source files are in the same directory .... ActorBase0\sources

That comment is a little confusing. Your Bridge class should be in a directory called ActorBase0\classes, so just to make sure we are all on the same page, can you tell us which directory each source file is in and what the package declaration in each file is.
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
Roger F. Gay wrote:I have:

Place is also in package ActorBase0.classes and the source files are in the same directory .... ActorBase0\sources

That comment is a little confusing. Your Bridge class should be in a directory called ActorBase0\classes, so just to make sure we are all on the same page, can you tell us which directory each source file is in and what the package declaration in each file is.


Classes Place and Bridge are both members of the ActorBase0.classes package.
Source files Place.java and Bridge.java are both in ActorBase0\sources

As indicated by the -d option, all compiled classes should be placed in subdirectory ActorBase0\classes.

This works properly when I don't use the -sourcepath option and instead list all of the source files, including the superclass.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger F. Gay wrote:Classes Place and Bridge are both members of the ActorBase0.classes package.
Source files Place.java and Bridge.java are both in ActorBase0\sources

Then that is probably your problem. Using the option
-sourcepath ActorBase0\sources
means that the compiler will look for classes in that directory, but it will use the fully qualified name of the class it is looking for. In this case it is looking for
ActorBase0.classes.Place
so it is actually trying to find a file called
ActorBase0\sources\ActorBase0\classes\Place.java

The directory structure that you put your .java file in needs to match the package name.
 
Roger F. Gay
Ranch Hand
Posts: 408
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joanne Neal wrote:
Roger F. Gay wrote:Classes Place and Bridge are both members of the ActorBase0.classes package.
Source files Place.java and Bridge.java are both in ActorBase0\sources

Then that is probably your problem. Using the option
-sourcepath ActorBase0\sources
means that the compiler will look for classes in that directory, but it will use the fully qualified name of the class it is looking for. In this case it is looking for
ActorBase0.classes.Place
so it is actually trying to find a file called
ActorBase0\sources\ActorBase0\classes\Place.java

The directory structure that you put your .java file in needs to match the package name.


To test, I created the ActorBase0\sources\ActorBase0\classes\ directory and copied all the source files into it. Got the same error.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roger F. Gay wrote:To test, I created the ActorBase0\sources\ActorBase0\classes\ directory and copied all the source files into it. Got the same error.

I wasn't actually suggesting you use that directory structure.
Let's go back to basics, so that we have everything in a sensible place
In your base directory you should have a directory called source and a directory called classes
In your source directory you should have a subdirectory called ActorBase0\classes
You need to put your two source files in this directory.
Then from your base directory use the command
javac -d classes -sourcepath source source\ActorBase0\classes\Bridge.java

Basically the things you have to remember are
  • your package name has to match the directory structure that your source files are in
  • the directory specified in your sourcepath option has to be the parent directory of the top level of your source directory tree
  •  
    Roger F. Gay
    Ranch Hand
    Posts: 408
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    ...... success

    I knew putting sources and classes at the end seemed a little screwy. Now the structure is sources and classes at the top, with ActorBase0 as the package.

    Thanks!

     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!