Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

568
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!