Java - How to Compile a single file with Java Eclipse

14,250

Solution 1

Your class has to define a public static void main(String[] args) method. Then find the Java file in the project explorer, right-click on it, and choose "run as Java application".

Solution 2

In addition to the info in the answer already selected, others having this or a similar problem should chech the "Run Configurations" panel to make sure the setting are correct for the app you are launching. Check

Run Configurations

Run Configurations

Share:
14,250
madhu131313
Author by

madhu131313

I code in whichever language is needed for the idea to be executed rightly!

Updated on June 18, 2022

Comments

  • madhu131313
    madhu131313 about 2 years

    I am trying to compile one file in a java project, but I am seeing other result (result of another file ) in console. I even tried Ctrl + F11 but the same thing happened

    In the dropdown of Run button of Java I am not finding the current file name but if I start a new project and run the file it is compiling. Note:I am a beginner in Java.

  • madhu131313
    madhu131313 over 11 years
    can I save this file with either names.PassOb.java or Block.java pastebin.com/t7Jq9sdm
  • Axel
    Axel over 11 years
    The file name has to be the same (+ extension ".java") as the public class (or interface) defined inside the file.