🕷️ Crawler Inspector

URL Lookup

Direct Parameter Lookup

Raw Queries and Responses

1. Shard Calculation

Query:
Response:
Calculated Shard: 144 (from laksa109)

2. Crawled Status Check

Query:
Response:

3. Robots.txt Check

Query:
Response:

4. Spam/Ban Check

Query:
Response:

5. Seen Status Check

ℹ️ Skipped - page is already crawled

đź“„
INDEXABLE
âś…
CRAWLED
2 days ago
🤖
ROBOTS ALLOWED

Page Info Filters

FilterStatusConditionDetails
HTTP statusPASSdownload_http_code = 200HTTP 200
Age cutoffPASSdownload_stamp > now() - 6 MONTH0.1 months ago
History dropPASSisNull(history_drop_reason)No drop reason
Spam/banPASSfh_dont_index != 1 AND ml_spam_score = 0ml_spam_score=0
CanonicalPASSmeta_canonical IS NULL OR = '' OR = src_unparsedNot set

Page Details

PropertyValue
URLhttps://www.baeldung.com/java-run-jar-with-arguments
Last Crawled2026-04-07 17:29:41 (2 days ago)
First Indexed2019-05-09 19:05:24 (6 years ago)
HTTP Status Code200
Meta TitleRun a Java Application from the Command Line | Baeldung
Meta DescriptionLearn how to create and run a JAR application with or without command-line arguments
Meta Canonicalnull
Boilerpipe Text
1. Overview Typically, every meaningful application includes one or more JAR files as dependencies. But there are times a JAR file itself represents a standalone application or a web application. Here we’ll focus on the standalone application scenario. From now on, we’ll refer to it as a JAR application. In this tutorial, we’ll first learn how to create a JAR application. Later, we’ll learn how to run a JAR application with or without command-line arguments. 2. Create a JAR Application A  JAR file can contain one or more main classes. Each main class is the entry point of an application. So, a JAR file can theoretically contain more than one application, but it has to contain at least one main class to be able to run. A JAR file can have one entry point set in its manifest file . In this case, the JAR file is an executable JAR . The main class has to be included in that JAR file. First, let’s see a quick example of how to compile our classes and create an executable JAR with a manifest file: $ javac com/baeldung/jarArguments/*.java $ jar cfm JarExample.jar ../resources/example_manifest.txt com/baeldung/jarArguments/*.class A nonexecutable JAR is simply a JAR file that doesn’t have a Main-Class defined in the manifest file. As we’ll see later, we can still run a main class that’s contained in the JAR file itself. Here’s how we would create a nonexecutable JAR without a manifest file: $ jar cf JarExample2.jar com/baeldung/jarArguments/*.class 3. Java Command-Line Arguments Just like any application, a JAR application accepts any number of arguments, including zero arguments. It all depends on the application’s need. This allows the user to specify configuration information when the application is launched. As a result, the application can avoid hard-coded values, and it still can handle many different use cases. An argument can contain any alphanumeric characters, unicode characters and possibly some special characters allowed by the shell, for example, @. Arguments are separated by one or more spaces. If an argument needs to contain spaces, the spaces have to be enclosed between quotes. Either single quotes or double quotes work fine. Usually, for a typical Java application, when invoking the application, the user enters command-line arguments after the name of the class. However, that’s not always the case for JAR applications. As we discussed, the entry point of a Java main class is the main method . The arguments are all String s and are passed to the main method as a String array. That said, inside the application, we can convert any element of the String array to other data types, such as char , int , double , their wrapper classes  or other appropriate types. 4. Run an Executable JAR with Arguments Let’s see the basic syntax for running an executable JAR file with arguments: java -jar jar-file-name [args …] The executable JAR created earlier is a simple application that just prints out the arguments passed in. We can run it with any number of arguments. Here’s an example with two arguments: $ java -jar JarExample.jar "arg 1" arg2@ We’ll see this output in the console: Hello Baeldung Reader in JarExample! There are 2 argument(s)! Argument(1):arg 1 Argument(2):arg2@ So, when invoking an executable JAR, we don’t need to specify the main class name on the command line. We simply add our arguments after the JAR file name. If we do provide a class name after the executable JAR file name, it simply becomes the first argument to the actual main class. Most times, a JAR application is an executable JAR. An executable JAR can have a maximum of one main class defined in the manifest file . Consequently, other applications in the same executable JAR file can’t be set in the manifest file, but we can still run them from the command line just like we would for a nonexecutable JAR. We’ll see exactly how in the next section. 5. Run a Nonexecutable JAR with Arguments To run an application in a nonexecutable JAR file, we have to use -cp option instead of -jar . We’ll use the -cp option (short for classpath) to specify the JAR file that contains the class file we want to execute: java -cp jar-file-name main-class-name [args …] As we can see,  in this case, we’ll have to include the main class name in the command line, followed by arguments. The nonexecutable JAR created earlier contains the same simple application. We can run it with any (including zero) arguments. Here’s an example with two arguments: $ java - cp JarExample2.jar com.baeldung.jarArguments.JarExample "arg 1" arg2@ And, just like we saw above, we’ll see this output: Hello Baeldung Reader in JarExample! There are 2 argument(s)! Argument(1):arg 1 Argument(2):arg2@ 6. Conclusion In this article, we learned two ways of running a JAR application on the command line with or without arguments. We also demonstrated that an argument could contain spaces and special characters (when allowed by the shell). The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member , start learning and coding on the project.
Markdown
![](https://www.facebook.com/tr?id=512471148948613&ev=PageView&noscript=1) [![The Baeldung logo](https://www.baeldung.com/wp-content/themes/baeldung/icon/logo.svg)](https://www.baeldung.com/ "Baeldung") - [![The Baeldung Logo](https://www.baeldung.com/wp-content/themes/baeldung/icon/logo.svg)](https://www.baeldung.com/ "Baeldung") - [Start Here](https://www.baeldung.com/start-here) - [Spring Courses ▼▲]() - [REST with Spring Boot The canonical reference for building a production grade API with Spring](https://www.baeldung.com/courses/rest-with-spring-boot-course "The “REST With Spring” Course") - [Learn Spring Security THE unique Spring Security education if you’re working with Java today](https://www.baeldung.com/courses/learn-spring-security-course) - [Learn Spring From no experience to actually building stuff​](https://www.baeldung.com/courses/learn-spring-course) - [Learn Spring Data JPA The full guide to persistence with Spring Data JPA](https://www.baeldung.com/courses/learn-spring-data-jpa-course) - [View All Spring Courses](https://www.baeldung.com/members/all-courses) - [Java Courses ▼▲]() - [Learn JUnit Master the most popular Java testing framework.](https://www.baeldung.com/courses/learn-junit-course) - [Learn Maven Simplify Your Build with Apache Maven](https://www.baeldung.com/courses/learn-maven-course) - [Learn Hibernate JPA Master persistence with the Java specification and Hibernate implementation](https://www.baeldung.com/courses/learn-hibernate-jpa-course) - [Learn Mockito Enhance your unit tests through practical mocking](https://www.baeldung.com/courses/learn-mockito-course) - [View All Courses](https://www.baeldung.com/members/all-courses) - [Pricing](https://www.baeldung.com/pricing) - [About ▼▲]() - [Full Archive The high level overview of all the articles on the site.](https://www.baeldung.com/full_archive) - [Baeldung Ebooks Discover all of our eBooks](https://www.baeldung.com/library/) - [About Baeldung About Baeldung.](https://www.baeldung.com/about) # Run a Java Application from the Command Line Last updated: February 20, 2026 ![](https://secure.gravatar.com/avatar/f7bfa7ac878afa29edaf04960cdc924cd1d8228a4dbc84dbd410e20fb76b2e4c?s=50&r=g) Written by: [baeldung](https://www.baeldung.com/author/baeldung "Posts by baeldung") ![](https://www.baeldung.com/wp-content/uploads/custom_avatars/Eric-Martin-150x150.jpg) Reviewed by: [Eric Martin](https://www.baeldung.com/editor/eric-editor "Reviewed by Eric Martin") - [DevOps](https://www.baeldung.com/category/devops) - [Java](https://www.baeldung.com/category/java) - [CLI](https://www.baeldung.com/tag/cli) - [JAR](https://www.baeldung.com/tag/jar) ## 1\. Overview Typically, every meaningful application includes one or more JAR files as dependencies. But there are times a JAR file itself represents a standalone application or a web application. Here we’ll focus on the standalone application scenario. From now on, we’ll refer to it as a JAR application. In this tutorial, we’ll first learn how to create a JAR application. Later, we’ll learn how to **run a JAR application with or without command-line arguments.** ## Further reading: ## [Run JUnit Test Cases From the Command Line](https://www.baeldung.com/?post_type=post&p=108700) Learn how to run JUnit 5 tests directly from the command line with and without Maven [Read more](https://www.baeldung.com/?post_type=post&p=108700) → ## [Command-Line Arguments in Java](https://www.baeldung.com/?post_type=post&p=59285) Explore how to configure your Java applications using command-line arguments. [Read more](https://www.baeldung.com/?post_type=post&p=59285) → ## [Command-Line Arguments in Spring Boot](https://www.baeldung.com/?post_type=post&p=31683) Learn how to pass arguments from command line into your Spring Boot application [Read more](https://www.baeldung.com/?post_type=post&p=31683) → ## 2\. Create a **JAR** Application A [JAR file](https://www.baeldung.com/java-create-jar) can contain one or more main classes. **Each main class is the entry point of an application.** So, a JAR file can theoretically contain more than one application, but it has to contain at least one main class to be able to run. **A JAR file can have one entry point set in its [manifest file](https://www.baeldung.com/java-jar-executable-manifest-main-class).** In this case, the JAR file is an [executable JAR](https://www.baeldung.com/executable-jar-with-maven). The main class has to be included in that JAR file. First, let’s see a quick example of how to compile our classes and create an executable JAR with a manifest file: ``` Copy ``` A nonexecutable JAR is simply a JAR file that doesn’t have a *Main-Class* defined in the manifest file. As we’ll see later, we can still run a main class that’s contained in the JAR file itself. Here’s how we would create a nonexecutable JAR without a manifest file: ``` $ jar cf JarExample2.jar com/baeldung/jarArguments/*.classCopy ``` ## 3\. Java Command-Line Arguments Just like any application, a JAR application accepts any number of arguments, including zero arguments. It all depends on the application’s need. This allows the user to **specify configuration information when the application is launched.** As a result, the application can avoid hard-coded values, and it still can handle many different use cases. An argument can contain any alphanumeric characters, unicode characters and possibly some special characters allowed by the shell, for example, @. **Arguments are separated by one or more spaces.** If an argument needs to contain spaces, the spaces have to be enclosed between quotes. Either single quotes or double quotes work fine. Usually, for a typical Java application, when invoking the application, the user enters command-line arguments after the name of the class. However, that’s not always the case for JAR applications. As we discussed, the entry point of a Java main class is the [main method](https://www.baeldung.com/java-main-method). The **arguments are all *String*s** and are passed to the main method as a *String* array. That said, inside the application, we can convert any element of the *String* array to other data types, such as *char*, *int*, *double*, their [**wrapper classes**](https://www.baeldung.com/java-wrapper-classes) or other appropriate types. ## 4\. Run an Executable **JAR** with Arguments Let’s see the basic syntax for running an executable JAR file with arguments: ***java -jar jar-file-name \[args …\]*** The executable JAR created earlier is a simple application that just prints out the arguments passed in. We can run it with any number of arguments. Here’s an example with two arguments: ``` $ java -jar JarExample.jar "arg 1" arg2@Copy ``` We’ll see this output in the console: ``` Copy ``` So, **when invoking an executable JAR, we don’t need to specify the main class name on the command line.** We simply add our arguments after the JAR file name. If we do provide a class name after the executable JAR file name, it simply becomes the first argument to the actual main class. Most times, a JAR application is an executable JAR. An executable JAR can have a maximum of one main class defined in the [manifest file](https://www.baeldung.com/java-jar-executable-manifest-main-class). Consequently, other applications in the same executable JAR file can’t be set in the manifest file, but we can still run them from the command line just like we would for a nonexecutable JAR. We’ll see exactly how in the next section. ## 5\. Run a Nonexecutable **JAR** with Arguments To run an application in a nonexecutable JAR file, we have to use *\-cp* option instead of *\-jar*. We’ll use the *\-cp* option (short for classpath) to specify the JAR file that contains the class file we want to execute: ***java -cp jar-file-name main-class-name \[args …\]*** As we can see, **in this case, we’ll have to include the main class name in the command line, followed by arguments.** The nonexecutable JAR created earlier contains the same simple application. We can run it with any (including zero) arguments. Here’s an example with two arguments: ``` $ java -cp JarExample2.jar com.baeldung.jarArguments.JarExample "arg 1" arg2@Copy ``` And, just like we saw above, we’ll see this output: ``` Copy ``` ## 6\. Conclusion In this article, we learned two ways of running a JAR application on the command line with or without arguments. We also demonstrated that an argument could contain spaces and special characters (when allowed by the shell). The code backing this article is available on GitHub. Once you're **logged in as a [Baeldung Pro Member](https://www.baeldung.com/members/)**, start learning and coding on the project. Course – LS – NPI (cat=Java) ![announcement - icon](https://www.baeldung.com/wp-content/uploads/2022/04/announcement-icon.png) **Get started with Spring Boot** and with core Spring, through the *Learn Spring* course: **[\>\> CHECK OUT THE COURSE](https://www.baeldung.com/course-ls-NPI-9-7Y5va)** ![The Baeldung logo](https://www.baeldung.com/wp-content/themes/baeldung/icon/logo.svg) #### Courses - [All Courses](https://www.baeldung.com/courses/all-courses) - [Baeldung All Access](https://www.baeldung.com/courses/all-access) - [Baeldung All Team Access](https://www.baeldung.com/courses/all-access-team) - [Login Course Platform](https://www.baeldung.com/members/account) #### Series - [Java “Back to Basics” Tutorial](https://www.baeldung.com/java-tutorial) - [Learn Spring Boot Series](https://www.baeldung.com/spring-boot) - [Spring Tutorial](https://www.baeldung.com/spring-tutorial) - [Get Started with Java](https://www.baeldung.com/get-started-with-java-series) - [Spring Framework Introduction](https://www.baeldung.com/spring-intro) - [All About String in Java](https://www.baeldung.com/java-string) - [Security with Spring](https://www.baeldung.com/security-spring) #### About - [About Baeldung](https://www.baeldung.com/about) - [The Full Archive](https://www.baeldung.com/full_archive) - [Editors](https://www.baeldung.com/editors) - [Our Partners](https://www.baeldung.com/partners/) - [Partner with Baeldung](https://www.baeldung.com/partners/work-with-us) - [eBooks](https://www.baeldung.com/library/) - [FAQ](https://www.baeldung.com/library/faq) - [![](https://www.baeldung.com/wp-content/uploads/2024/09/pro-icon.svg)Baeldung Pro](https://www.baeldung.com/members/) - [Terms of Service](https://www.baeldung.com/terms-of-service) - [Privacy Policy](https://www.baeldung.com/privacy-policy) - [Company Info](https://www.baeldung.com/baeldung-company-info) - [Contact](https://www.baeldung.com/contact) Privacy Manager ![The Baeldung Logo](https://www.baeldung.com/wp-content/themes/baeldung/icon/whiteleaf.svg) Follow the Java Category ![](https://www.baeldung.com/wp-content/uploads/2017/07/follow-the-spring.png) Follow the Java category to get regular info about the new articles and tutorials we publish here. ![](https://www.baeldung.com/wp-content/themes/baeldung/icon/logo.svg) ## Looks like your ad blocker is on. × We rely on ads to keep creating quality content for you to enjoy for free. Please support our site by disabling your ad blocker or, use **Baeldung Pro** for a clean, absolutely **no-ads** reading experience. Disable [Baeldung Pro![](https://www.baeldung.com/wp-content/themes/baeldung/icon/pro-icon.svg)](https://www.baeldung.com/members) Continue without supporting us #### Choose your Ad Blocker - Adblock Plus - Adblock - Adguard - Ad Remover - Brave - Ghostery - uBlock Origin - uBlock - UltraBlock - Other 1. In the extension bar, click the AdBlock Plus icon 2. Click the large blue toggle for this website 3. Click refresh 1. In the extension bar, click the AdBlock icon 2. Under "Pause on this site" click "Always" 1. In the extension bar, click on the Adguard icon 2. Click on the large green toggle for this website 1. In the extension bar, click on the Ad Remover icon 2. Click "Disable on This Website" 1. In the extension bar, click on the orange lion icon 2. Click the toggle on the top right, shifting from "Up" to "Down" 1. In the extension bar, click on the Ghostery icon 2. Click the "Anti-Tracking" shield so it says "Off" 3. Click the "Ad-Blocking" stop sign so it says "Off" 4. Refresh the page 1. In the extension bar, click on the uBlock Origin icon 2. Click on the big, blue power button 3. Refresh the page 1. In the extension bar, click on the uBlock icon 2. Click on the big, blue power button 3. Refresh the page 1. In the extension bar, click on the UltraBlock icon 2. Check the "Disable UltraBlock" checkbox 1. Please disable your Ad Blocker Go Back
Readable Markdown
## 1\. Overview Typically, every meaningful application includes one or more JAR files as dependencies. But there are times a JAR file itself represents a standalone application or a web application. Here we’ll focus on the standalone application scenario. From now on, we’ll refer to it as a JAR application. In this tutorial, we’ll first learn how to create a JAR application. Later, we’ll learn how to **run a JAR application with or without command-line arguments.** ## 2\. Create a **JAR** Application A [JAR file](https://www.baeldung.com/java-create-jar) can contain one or more main classes. **Each main class is the entry point of an application.** So, a JAR file can theoretically contain more than one application, but it has to contain at least one main class to be able to run. **A JAR file can have one entry point set in its [manifest file](https://www.baeldung.com/java-jar-executable-manifest-main-class).** In this case, the JAR file is an [executable JAR](https://www.baeldung.com/executable-jar-with-maven). The main class has to be included in that JAR file. First, let’s see a quick example of how to compile our classes and create an executable JAR with a manifest file: ``` $ javac com/baeldung/jarArguments/*.java $ jar cfm JarExample.jar ../resources/example_manifest.txt com/baeldung/jarArguments/*.class ``` A nonexecutable JAR is simply a JAR file that doesn’t have a *Main-Class* defined in the manifest file. As we’ll see later, we can still run a main class that’s contained in the JAR file itself. Here’s how we would create a nonexecutable JAR without a manifest file: ``` $ jar cf JarExample2.jar com/baeldung/jarArguments/*.class ``` ## 3\. Java Command-Line Arguments Just like any application, a JAR application accepts any number of arguments, including zero arguments. It all depends on the application’s need. This allows the user to **specify configuration information when the application is launched.** As a result, the application can avoid hard-coded values, and it still can handle many different use cases. An argument can contain any alphanumeric characters, unicode characters and possibly some special characters allowed by the shell, for example, @. **Arguments are separated by one or more spaces.** If an argument needs to contain spaces, the spaces have to be enclosed between quotes. Either single quotes or double quotes work fine. Usually, for a typical Java application, when invoking the application, the user enters command-line arguments after the name of the class. However, that’s not always the case for JAR applications. As we discussed, the entry point of a Java main class is the [main method](https://www.baeldung.com/java-main-method). The **arguments are all *String*s** and are passed to the main method as a *String* array. That said, inside the application, we can convert any element of the *String* array to other data types, such as *char*, *int*, *double*, their [**wrapper classes**](https://www.baeldung.com/java-wrapper-classes) or other appropriate types. ## 4\. Run an Executable **JAR** with Arguments Let’s see the basic syntax for running an executable JAR file with arguments: ***java -jar jar-file-name \[args …\]*** The executable JAR created earlier is a simple application that just prints out the arguments passed in. We can run it with any number of arguments. Here’s an example with two arguments: ``` $ java -jar JarExample.jar "arg 1" arg2@ ``` We’ll see this output in the console: ``` Hello Baeldung Reader in JarExample! There are 2 argument(s)! Argument(1):arg 1 Argument(2):arg2@ ``` So, **when invoking an executable JAR, we don’t need to specify the main class name on the command line.** We simply add our arguments after the JAR file name. If we do provide a class name after the executable JAR file name, it simply becomes the first argument to the actual main class. Most times, a JAR application is an executable JAR. An executable JAR can have a maximum of one main class defined in the [manifest file](https://www.baeldung.com/java-jar-executable-manifest-main-class). Consequently, other applications in the same executable JAR file can’t be set in the manifest file, but we can still run them from the command line just like we would for a nonexecutable JAR. We’ll see exactly how in the next section. ## 5\. Run a Nonexecutable **JAR** with Arguments To run an application in a nonexecutable JAR file, we have to use *\-cp* option instead of *\-jar*. We’ll use the *\-cp* option (short for classpath) to specify the JAR file that contains the class file we want to execute: ***java -cp jar-file-name main-class-name \[args …\]*** As we can see, **in this case, we’ll have to include the main class name in the command line, followed by arguments.** The nonexecutable JAR created earlier contains the same simple application. We can run it with any (including zero) arguments. Here’s an example with two arguments: ``` $ java -cp JarExample2.jar com.baeldung.jarArguments.JarExample "arg 1" arg2@ ``` And, just like we saw above, we’ll see this output: ``` Hello Baeldung Reader in JarExample! There are 2 argument(s)! Argument(1):arg 1 Argument(2):arg2@ ``` ## 6\. Conclusion In this article, we learned two ways of running a JAR application on the command line with or without arguments. We also demonstrated that an argument could contain spaces and special characters (when allowed by the shell). The code backing this article is available on GitHub. Once you're **logged in as a [Baeldung Pro Member](https://www.baeldung.com/members/)**, start learning and coding on the project.
Shard144 (laksa)
Root Hash17258965353624827544
Unparsed URLcom,baeldung!www,/java-run-jar-with-arguments s443