不能从命令行运行我的程序 [英] Cant run my programme from command line
问题描述
我有一个main方法创建一个逻辑类的实例
I have a main method that creates an instance of a logic class
public static void main(String[] args) {
try {
Logic logic = new Logic(args[0]);
....... do some stuff here
} catch (Exception e) {
System.out.println("Error Encountered Details: " + e);
}
}
事情是程序需要一个csv文件运行,我已经把它在与.jar文件相同的目录,但是当我从命令行运行我只是得到java.lang.arrayindexoutofbounds(0)错误
the thing is that the programme requires a csv file to run, i have put it in the same directory as the .jar file but when i run from the command line i just get java.lang.arrayindexoutofbounds(0) error
我做错了什么
感谢
推荐答案
看起来像:
java -cp {name_of_jar} {name_of_class} {name_of_csv}
您似乎没有提供.csv文件名(它将在 args [0]
)?
It looks like you're not supplying the .csv file name (which will go in args[0]
) ?
上述假设主类未在.jar清单中定义。如果是,则使用:
The above assumes that the main class is not defined in your .jar manifest. if it is, then use:
java -jar {name_of_jar} {name_of_csv}
这是一个很好的做法,检查 args []
数组btw并生成诸如缺少.csv文件名或类似内容的消息,以避免令人讨厌的异常/堆栈跟踪。
It's a good practise to check the args[]
array for the required info, btw, and generate a message such as "Missing .csv file name" or similar to avoid a nasty exception/stack trace.
这篇关于不能从命令行运行我的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!