Compile multiple java files in the same folder

4

I made a very simple Java program, using notepad and compiling by CMD . The problem is that even the files being in the same folder, the class that has the main() method does not compile.

The following is the code below:

Main class

public class Main {
    public static void main(String[] args) {
        Nada nada = new Nada();

        nada.showVars();
        nada.setName("maisnada");
        nada.setN(16);
        System.out.println();
        nada.showVars();
    }
}

Class Nothing

public class Nada {
    private String nome;
    private int numeroQualquer;

    public Nada() {
        this.nome = "nada";
        this.numeroQualquer = 3;
    }

    public void setName(String nome) {
        this.nome = nome;
    }

    public void setN(int n) {
        this.numeroQualquer = n;
    }

    public void showVars() {
        System.out.println(nome);
        System.out.println(numeroQualquer);
    }
}

When I try to compile Main.java, it gives the following error in CMD :

Main.java:3 error: cannot find symbol
               Nada nada = new Nada();
               ^
   symbol:   class Nada
   location: class Main
Main.java:3 error: cannot find symbol
               Nada nada = new Nada();
                               ^
   symbol:   class Nada
   location: class Main
2 errors

Since the two files, Main.java and Nada.java, are in the same folder, and Nada.java compiled normally.

EDIT:

I was able to solve the problem, it was the environment variable CLASSPATH , it was as %JAVA_HOME%\lib instead of .;%JAVA_HOME%\lib .

The command I used to compile was this:

javac Main.java

Thanks to all who responded.

    
asked by anonymous 18.09.2015 / 06:55

2 answers

4

You need to compile .java and not just Main files. As you have not put which command you are using to compile, I suppose this is your error

To do this you can run the command:

  

javac * .java

The * is a very common wildcard that means everything or all . In this case * .java means all .java files in this folder.

    
18.09.2015 / 13:10
0

Just do the following command:

javac diretorio/*.java
    
18.09.2015 / 13:55