Reputation: 11
I have few classes in the same package demo, but the most important are Server.java and MyServerImpl.java. In Server.java I have this code
package demo;
public class Server
{public static void main( String[] args ) throws Exception
{
MyServerImpl s = new MyServerImpl("blablabla");
...
}
And the class MyServerImpl
package demo;
public class MyServerImpl extends MyServerPOA {
private String location;
public MyServerImpl( String location )
{
this.location = location;
}
public void add ( String value ){
System.out.println("name " + value + location );
}
}
When I try to compile with javac I have this error
cannot find symbol
symbol : class MyServerImpl
location: class demo.Server
MyServerImpl s = new MyServerImpl("blablabla");
I try to compile with this command javac project/demo/Server.java
and when I am in the demo folder
javac Server.java
but still get the same error
Upvotes: 0
Views: 1389
Reputation: 11867
To expand on my comment:
When javac
looks for classes, the folders it looks in are based off of the fully qualified name for the class.
So in your case, the fully qualified name for MyServerImpl
is demo.MyServerImpl
. Thus, when the compiler encounters MyServerImpl
in Server.java
, it looks for a folder called demo
, and if it finds that folder, looks for MyServerImpl.java
.
If you cd
'd into demo, this will cause compilation to fail, because demo
obviously doesn't contain itself (otherwise you might have some broken OSs).
So what you need to do is cd
into the folder above demo
. So for example, if your file hierarchy is src
as root, with the demo
package inside, with Server.java
and MyServerImpl.java
inside:
cd
into src
, so that if you ls
/dir
, demo
is (one of) the folder(s) that shows upjavac demo/Server.java
Upvotes: 1