Reputation: 71
I've problem compiling these java files .I have a class MeterMovementService.java and an interface MeterMovementServiceMBean.java . The class is implementing this interface . And i compiled the interface first .Both the class and interface resides in same package . But when I try to compile the class it gives error as :
MeterMovementService.java:2: error: cannot find symbol
public class MeterMovementService implements MeterMovementServiceMBean
^
symbol: class MeterMovementServiceMBean
1 error
Here is the code for the MeterMovementService.java class
My class does'nt have dependency.It just implements the interface.
public class MeterMovementService implements MeterMovementServiceMBean {
private String message = "Sorry no message today";
public String getMessage(){
return message;
}
public void setMessage(String message){
this.message = message;
}
public void printMessage(){
System.out.println(message);
}
public void start() throws Exception{
System.out.println(">>>>Starting with message=" + message);
}
public void stop() throws Exception{
System.out.println(">>>>Stopping with message=" + message);
}
}
Upvotes: 0
Views: 645
Reputation: 71
javac -d . *.java
compiles all the java files in the current directory and packages the compiled classfiles according to their package structure .
Upvotes: 1
Reputation: 213261
You need to ensure that your class files are placed under the package folder. For e.g. if your interface is defined under package - pkg1
, your class file should be under pkg1
subfolder.
Your directory structure should be like this:
srcfolder -+
+- pkg1 -+- MeterMovementServiceMBean.class
| +- MeterMovementService.class
|
+- MeterMovementService.java
+- MeterMovementServiceMBean.java
Either you have to move the class files manually, or even better, you can compile your .java files using the below command, to let the compiler handle it all for you:
javac -d . MeterMovementServiceMBean.java
Upvotes: 1