开发者

Passing arguments to JAR which is required by Java Interpreter

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 J开发者_如何学运维AR file for my application and how can i overcome need of arguments.


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!");


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);
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜