Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

566
Visualizações
Eclipse compiled files are not runnable by java command

When you write a simple Java Application in Eclipse in automatically compiles those files and stores them in the bin/ folder of the root folder of the project.

Now if I navigate to the /bin folder and to the folder that contains the .class file I want to run via the java command below I am getting the following error - :

java A Error: Could not find or load main class A

Class A:

package assurance;

public class A {

    public static void main(String[] args) {
        System.out.println("Hello World");
    }
}

While the class A has a main method and runs fine when I right click on the file and do a Run As Java Application. But it does not run from the command like java command.

Why is this happening ?

Update:

Tried with the following commands-:

java -cp "A.class" assurance.A
java -cp "A" assurance.A
java -cp "*" assurance.A
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

It works in Eclipse, because Eclipse just runs it with correct -cp and correct command :)

Run your code with the following command: java -cp "./" assurance.A ("" for some odd cmd interpreters like Windows XP) it is important that the command is run from the "default package" directory (top-level package directory).

Java interprets package name (assurance) as directory path to the class file. Imagine if it replaces . with / and adds .class extension (assurance.A => ./assurance/A.class)

More details here: http://docs.oracle.com/javase/7/docs/technotes/tools/windows/classpath.html

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda