JAVA 类路径传递文件作为命令行参数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12709796/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 09:55:36  来源:igfitidea点击:

JAVA classpath pass file as command line argument

javafilecommand-line-arguments

提问by Dattaprasad Patil

I have a program which is located in

我有一个程序位于

say

$A430CLASS/com.airbus.adcsip.batch.GlobalReportBatch

$A430CLASS is the path where my class file is present.

$A430CLASS 是我的类文件所在的路径。

i want to run it through shell script so i entered following command :

我想通过 shell 脚本运行它,所以我输入了以下命令:

java -classpath $A430CLASS/com.airbus.adcsip.batch.GlobalReportBatch $A430CONF/batch.properties

$A430CONF is the path where the batch.properties file is present. GlobalReportBatch is my class file nameAs you can see i want to pass this batch.properties file as argument to my java program. but when i run my script it tries to replace "." in batch.props file to "/" it gives me NoClassDefFounderror.

$A430CONF 是 batch.properties 文件所在的路径。GlobalReportBatch 是我的类文件名如您所见,我想将此 batch.properties 文件作为参数传递给我的 java 程序。但是当我运行我的脚本时,它会尝试替换“.” 在 batch.props 文件中到“/”它给了我NoClassDefFound错误。

回答by Jesper

What you put after the -classpathoption must be a list of directories and JAR files, separated by :(on Unix-like operating systems) or ;(on Windows).

您在-classpath选项后面放置的必须是目录和 JAR 文件的列表,以:(在类 Unix 操作系统上)或;(在 Windows 上)分隔。

Look at what you are passing:

看看你通过的是什么:

-classpath $A430CLASS/com.airbus.adcsip.batch.GlobalReportBatch

-classpath $A430CLASS/com.airbus.adcsip.batch.GlobalReportBatch

Remove the slash /between $A430CLASSand your class name; replace it by a space:

删除和你的类名/之间的斜线$A430CLASS;用空格替换它:

-classpath $A430CLASS com.airbus.adcsip.batch.GlobalReportBatch

-classpath $A430CLASS com.airbus.adcsip.batch.GlobalReportBatch

So the entire line becomes:

所以整行变成:

java -classpath $A430CLASS com.airbus.adcsip.batch.GlobalReportBatch $A430CONF/batch.properties