3

When i execute my java application i need to pass arguments which is needed by Java interpreter for Flash image.

for eg. java -sum_arg Demo

Now i want to create JAR file for my application and how can i overcome need of arguments.

Vijay
  • 31
  • 1
  • 2

2 Answers2

6

You can pass arguments to Java applications packed into .jar files just as you can with single .class files:

java -jar MyApp.jar anArgument

If you care about the UI case where a user simply double-clicks the .jar file to run your application, then you might want to consider using a real UI (using Swing, for example).

A simple way to get input this way would be with a JOptionPane:

String myInput = JOptionPane.showInputDialog("Enter something!");
Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
0

If you have not any class path dependencies

java -jar test.jar "arg1" "arg2"

If you have any class-path dependencies

java -cp classpath-dependencies -jar test.jar "arg1" "arg2"

In swing we can get parameter from command line argument.

public static void main(String[] args)
{
    for(String arg : args)
        System.out.println(arg);
}
Mack
  • 403
  • 3
  • 11