-2

I downloaded a simple java app and I want to know which file I need to run to start. There are several classes in the project and I do not know which one is the main one. Thank you.

nipuro
  • 310
  • 5
  • 22

2 Answers2

1

Search for the class with the main method, that is the method where program execution starts. It looks like

public static void main(String[] args) { ... }

It's inside the class Main.java of your project:

public class Main extends Application {

    public static void main(final String[] args) {
        launch(args);
    }

    // [...]
}

Open the project in an IDE and run this class. Or do it manually in the console like:

javac Main.java
java Main

Only .jar files can automatically be started like .exe files. Your project only contains code and you will need to compile and run it on your own.

Zabuzard
  • 25,064
  • 8
  • 58
  • 82
  • This is valid for all java projects ? A project has only one class with a main method ? – nipuro Mar 08 '18 at 14:59
  • No, it could have multiple. You will then need to find the one that is meant to start the application. For example there could be other `main` methods used for debugging purpose which start some sub-applications. A C-program often has multiple `.exe` files too if you take a look at some of your installed apps on your computer. The programmer should clearly indicate which one is the **main** application. For example by including a *readme* file. – Zabuzard Mar 08 '18 at 15:11
0

You should have public static void method called "main" taking array of String as parameter in one of the classes. Something like below

public static void main(String... args) {
    System.out.println("test");
}

This is your entry point.

@Edit OP added code so here is an answer update: Your entry point is in class Main and method is

public static void main(final String[] args

If you're using intellij just run click on this method and select Run "Main.main()"

Rafał Pydyniak
  • 539
  • 4
  • 11