There are several ways to execute our new application. In the Building the application section, we saw that all of the compiled classes are stored by IntelliJ IDEA (using the built-in Maven) in the target folder. This means that we can execute the application by using the java tool and listing the folder target with the -classpath option.
To do that, open a Command Prompt or Terminal window and go to the root directory of our new project. If you are not sure where it is, look at the top line of the IntelliJ IDEA window that shows the full path to it. Once you are in the project root directory (it is the folder where the pom.xml file is located), run the following command:
![](assets/dad25f60-410a-4c64-9847-d83b2932c7f5.png)
In the preceding screenshot, you can see that the -classpath option (we used the short version, -cp, instead) has listed the directory where all of the classes are compiled. After that, we have typed the name of the com.packt.javapath.ch04demo.MyApplication main class, because we have to tell the java tool which class is an entry point to the application and contains the main() method. Then, we have typed 2 as an input parameter to the main class. As you may recall, the main() method expects it to be an integer.
When we run that command, the result shows the output in the expected format: 2 * 2 = 4.
Alternatively, we could collect all of the compiled classes in a myapp.jar file and run a similar java command with the myapp.jar file listed on the classpath:
![](assets/68445744-4225-4d7a-a13a-b29e1f44445e.png)
In the preceding screenshot, you can see that we entered the target folder and its classes subfolder first, then collected its content (all of the compiled classes) into the myapp.jar file with the jar command. Then, we typed the java command and listed the myapp.jar file with the -classpath option. Since the myapp.jar file is in the current directory, we do not include any directory path. The result of the java command was the same as before: 2 * 2 = 4.
Another way to get to the project root directory is to just open a terminal window from IDE. In IntelliJ IDEA, you can do it by clicking on the Terminal link in the bottom-left corner:
![](assets/b634572c-f39d-48af-9664-10a12682bd46.png)
Then, we can type all of the preceding commands in the Terminal window inside the IDE.
But there is an even easier way to execute the application from the IDE without typing all of the preceding commands, which is the recommended way during the project development phase. It is your IDE, remember? We will demonstrate how to do it in the next section.