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.
Asked
Active
Viewed 2,398 times
-2
-
is the app a .jar or do you have .java files? – dave Mar 08 '18 at 14:16
-
I have the .java files. – nipuro Mar 08 '18 at 14:18
-
Are you using an ide? – dave Mar 08 '18 at 14:19
-
Yes, intellij idea. – nipuro Mar 08 '18 at 14:20
-
well the op says they have the .java files so it shouldn't bee too hard then, so you might post the file structure so might be some help also what kind of app it is too, or where you got the simple app – dave Mar 08 '18 at 14:22
-
This is the app: https://github.com/nhooyr/java-tanktank – nipuro Mar 08 '18 at 14:39
-
Search for the class with the `main` method. It's inside the class `Main.java` of your project. – Zabuzard Mar 08 '18 at 14:42
-
You should edit your question and include all those additional information, especially the link to the project. In the current state your question is too broad as it doesn't contain all information needed to form an adequate answer. – Zabuzard Mar 08 '18 at 14:49
2 Answers
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