Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8561121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:25:51+00:00 2026-06-11T16:25:51+00:00

I have a Main.java file and I want to run the program passing it

  • 0

I have a Main.java file and I want to run the program passing it test.txt

I know in command line I can write javac Main.java

After compiling I can write java Main test.txt and this will accomplish running the file and passing test.txt

If I wanted instead to be able to just write main test.txt and have that trigger my Main.class file to run is that possible and if so how?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:25:52+00:00Added an answer on June 11, 2026 at 4:25 pm

    (Edit: Based on your comment, let me expand to add a couple more situations)

    If your goal is to have someone else run your program who does not have Java installed, and you do not wish to have them install a Java runtime environment before running your app, what you need is a program that converts the .class or .jar files into a native executable for the platform you are using. How to do this has been covered in other questions, eg: Compiling a java program into an executable . Essentially, you use a program like JCG (GNU Compiler for Java) or Excelsior JET (a commercial product) to expand the byte code into full native code with a mini-JRE built in.

    If your goal is to save typing, there are a number of strategies. Others have suggested alias commands, which work well on linux.

    A slightly more portable option that you could ship with your program would be a shell script. Granted, shell scripts only run on linux or other OS’s with shell script interpreters installed.

    Here is an example shell script. You paste this into a text editor and save it as main with no extensio. The $1 passes the parameter argument fyi.

    #!/bin/sh
    java Main $1
    

    presuming you name your shell script just “main” with no extension, you could call main test.txt to execute your program now.

    If you are on Windows, you might want to create a windows shortcut, and point the shortcut to “java Main test.text”, using the full paths if necessary (if the paths are not already set). Of course, this does not make the parameter easy to change every time you run it, you would have to edit the shortcut.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a .jar file, which I can run on the command line: java
I have created a JAR file. Now, I created another Java program. I want
I have a java main application, and I want to use log4j. I don't
I have a small Java test app in Netbeans where the main() class reads
I wanted to run a .cmd file from Java. I have something which works
I have an java application which contains run.bat file as below: rem set path=D:/Applns/jdk1.5/bin
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
I have four activities namely, Demo_tabActivity.java [main activity] Tabhost.java The below two activities are
Example: For(int i=0; i<4; i++) playSound(Sound.wav); I have the following classes: Main import java.io.IOException;
I have read somewhere one of the main differences between Java and C++/C# is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.