Pergunta

I know this question has been asked and answered a number of times. But I somehow am not able to get this right. I have a package having the following structure

model/
   InputDetails.java
   RelationDetails.java

Now the file RelationDetails has the following structure:

package model;
public class RelationDetails {
     ....
}

And the file InputDetails has the following structure

package model;
public class InputDetails {
    .....
}

Now I have compiled the RelationDetails.java file that creates a RelationDetails.class file in the same directory. But when I try to compile the InputDetails.java file, It shows the error

Symbol not found

wherever RelationDetails has been used. Where am I going wrong??

Foi útil?

Solução

I'd recommend using an IDE like Eclipse or IntelliJ IDEA. They will do the compiling for you. Or use Ant, Gradle or Maven to compile. I am a professional Java developer and I cannot remember the last time I used javac from the command line. There's no need for it.

If you insist on using javac directly, either compile both files together from the appropriate source folder (the directory above "model").:

javac "model/InputDetails.java" "model/RelationDetails.java"

Or, if you want to compile them separately:

javac -classpath . "model/InputDetails.java"
javac -classpath . "model/RelationDetails.java"

The -classpath . bit adds the current folder to the classpath for the javac executable, so it can find the previously compiled class and you won't get the 'Symbol not found' errors.

Outras dicas

$ pwd
/tmp/model

$ ls
InputDetails.java  RelationDetails.java

$ javac  InputDetails.java  RelationDetails.java

$ ls *.class
InputDetails.class  RelationDetails.class

I am just tried in my eclipse nothing will be showing errors, better to user Eclipse or STS they will help you like this problems easily I think so..

compile with fully qualifier name.

javac model\YourClass.java
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top