Results 1 to 2 of 2
  1. #1
    jhoang is offline Member
    Join Date
    Jun 2013
    Posts
    5
    Rep Power
    0

    Default Running .jar through command line. Possible to customize how it executes?

    I have a jar that contains a program which brings up an JOptionPane giving you 3 options to chose (i.e. What would you like to do? option 1, 2 or 3). Is it possible to package the jar or structure your code so that when double clicking the jar will bring up the JOptionPane but when run through command line, the program will automatically execute option 3?

  2. #2
    AndrewM16921 is offline Senior Member
    Join Date
    Jan 2009
    Location
    CA, USA
    Posts
    264
    Rep Power
    6

    Default Re: Running .jar through command line. Possible to customize how it executes?

    Yes, you need to provide command arguments. So, if you run
    java -jar myjar.jar arg1 arg2

    public static void main(String[] args)

    args will contain: { "arg1", "arg2" }

    Then, you can determine the correct behavior based on the args.

Similar Threads

  1. Linux running/compiling from Command Line?
    By arcelivez in forum New To Java
    Replies: 4
    Last Post: 01-27-2012, 11:10 PM
  2. Replies: 9
    Last Post: 01-18-2012, 12:00 AM
  3. Running Main from Command Line
    By sriram56 in forum New To Java
    Replies: 2
    Last Post: 11-26-2011, 09:27 AM
  4. Error While Running Windows Command Line Instruction
    By divs1210 in forum AWT / Swing
    Replies: 5
    Last Post: 04-13-2011, 04:09 PM
  5. Running Jar file using command line through Java Codes
    By NaturalE in forum Advanced Java
    Replies: 2
    Last Post: 02-24-2011, 04:07 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •