12

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

Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60
Dilan
  • 1,389
  • 5
  • 14
  • 24
  • 1
    Note that you are wanting to read a property at runtime, not an environment (`System.getProperty("xxx")` vs `System.getenv("xxx")`). – trebor Aug 02 '22 at 01:27

3 Answers3

17

Try giving following command,

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

Note that the given parameters should be accessed from code as follow:

System.getProperty("configDir")
Community
  • 1
  • 1
Sathish
  • 4,975
  • 3
  • 18
  • 23
  • 1
    It work Sathish but when I put System.getenv("configDir") it prints null. Could you give a solution to this.... thanks – Dilan Jun 17 '15 at 12:00
  • 1
    Hi, use System.getProperty("configDir") insteadof getenv() method. – Sathish Jun 17 '15 at 12:06
  • 1
    Thanks a lot Sathish it works.... I ask this question if it is not a disturbance to u. When I run it through IDE the System.getenv("configDir") works fine. But when i run it through terminal using above command the System.getProperty("configDir") working fine.. I cannot think why is this... – Dilan Jun 17 '15 at 12:14
  • You are welcome Dilan, I did not get what is not working. Can you please explain? I'll try to help if i know the answer. Thanks ! – Sathish Jun 17 '15 at 14:21
3

Try this command

export VARNAME='variable-value'

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

Asif
  • 465
  • 5
  • 6
1

Your command should be like

java  -cp test-tool.jar -DconfigDir=/etc/myconfig-config/ service.ScriptGenerator $clinic_count $client_files_count 
Aakash
  • 2,029
  • 14
  • 22