Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing environment variable to a java class in command line

Tags:

java

I have a necessity to read some properties from a file located in local etc/myconfig-config/ folder. I need to give this file path in the command line. I have given it as mentioned below. But there is an error and it displays like

Error: Could not find or load main class test-tool.jar. 

the command given is

java  -cp -DconfigDir=/etc/myconfig-config/ test-tool.jar 
service.ScriptGenerator $clinic_count $client_files_count 

can anybody please help me to resolve this.

thanks

like image 589
Dilan Avatar asked Jun 17 '15 10:06

Dilan


3 Answers

Try giving following command,

java -DconfigDir=/etc/myconfig-config/ -cp test-tool.jar service.ScriptGenerator $clinic_count $client_files_count 
like image 184
Sathish Avatar answered Oct 18 '22 20:10

Sathish


Try this command

export VARNAME='variable-value'

Then run your Java main class from the same command line.

like image 31
Asif Avatar answered Oct 18 '22 22:10

Asif


Your command should be like

java  -cp test-tool.jar -DconfigDir=/etc/myconfig-config/ service.ScriptGenerator $clinic_count $client_files_count 
like image 36
Aakash Avatar answered Oct 18 '22 21:10

Aakash