Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have two classes Owning and OwningAccessor. The files are in the same directory.

public class Owning {
    String _name = "";
    public void printBanner()
    {
    }
    public void printOwning(double amount)
    {
        printBanner();

        //print details
        System.out.println("name:" + _name);
        System.out.println("amount:" + amount);
    }
}


public class OwningAccessor {
    public void access()
    {
        Owning o = new Owning();
        o.printOwning(500);
    }
}

When I tried to compile OwningAccessor with javac -cp . OwningAccessor.java, I got compilation error.

symbol  : class Owning
location: class smcho.OwningAccessor
        Owning o = new Owning();
        ^
OwningAccessor.java:6: cannot find symbol
symbol  : class Owning
location: class smcho.OwningAccessor
        Owning o = new Owning();
                   ^

What's wrong with this? The code compiles fine under eclipse IDE.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
301 views
Welcome To Ask or Share your Answers For Others

1 Answer

Ok, let's suppose you have the code distributed in files as follows

myproject
├── out
└── src
    ├── OwningAccessor.java
    └── Owning.java

Go to your command prompt, and change directory to myproject. Once there issue the following command:

javac -d out -sourcepath src src/OwningAccessor.java

I just tested it and it works just fine. Your compiled classes will be located in the out folder:

.
├── out
│?? ├── OwningAccessor.class
│?? └── Owning.class
└── src
    ├── OwningAccessor.java
    └── Owning.java

Compiling one class will trigger the compilation of all other dependent classes. The compiler will automatically look for them in the src folder.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...