Skip to content

Programming by Design

If you're not prepared to be wrong, you'll never come up with anything original. – Sir Ken Robinson

  • About
  • Java-PbD
  • C-PbD
  • ASM-PbD
  • Algorithms
  • Other

IntelliJ: Adding Command Line Arguments

Posted on September 10, 2021January 29, 2025 By William Jojo
Docs

(Updated January 29, 2025)

Overview

Using an IDE to build and run programs is typically only done during development. Many developed programs will run on servers without a text or GUI interface of any kind and will write errors and such to log files for review when something goes wrong.

Since these programs are often executed from scripts that invoke them through the JRE behind the scenes, a mechanism needs to be in place to pass additional information to the program. This is where the command-line interface comes into play.


Review – Arrays of Objects

In Chapter 9, there is a section on Arrays of Objects that touches on how to use args to get access to the data passed to the program.

As an application developer, you will need a method to simulate this from your IDE. This was done very quickly with IntelliJ IDEA.


From within IntelliJ, you will:

  • Select Run from the top menu.
  • Select Edit Configurations.

If there is a configuration already, change the Program Arguments and set them to the necessary values, and you’re done.

If you see

image showing edit configuration dialog

Select Add New Run Configuration, then select Application

image showing no run config created

Once that’s done, fill out the following values:

  • Name
  • Main class
  • Program Arguments

image showing where to make config changes

Select OK to save the configuration.

Post navigation

❮ Previous Post: bits
Next Post: Godbolt: Behind the Compiler ❯

Creative Commons License
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Copyright © 2018 – 2025 Programming by Design.