0

I have placed BasicAccountRule.drl in my web application at location : C:/workspace/exim_design/src/main/resources/rules/drl/inpatient/BasicAccountRule.drl

Now, I have been using code :

File file = new File ("C:/workspace/exim_design/src/main/resources/rules/drl/inpatient/BasicAccountRule.drl");

This is working fine on my system, but while I am trying to run this code on another system I am getting error : java.io.FileNotFoundException

I know I am getting this error because I have hardcoded file path. And ( C:/workspace/exim_design ) will be different for every system/server.

So, how to make this path dynamic and use inside:

File file = new File () , so that it will run on every machine.

shyam
  • 9,134
  • 4
  • 29
  • 44

1 Answers1

2

You can set the values in a property file and modify it on every system.

You can set an environment variable.

You may use a relative path instead of an absolute one to read a file in your application classpath.

Michael Laffargue
  • 10,116
  • 6
  • 42
  • 76
  • this application will run on multiple machines ,so it won't be possible to change value in properties file for every machine. And could you please let me know how to implement relative path in this code ? – user2652907 Aug 14 '13 at 10:58
  • `new File ("../../inpatient/BasicAccountRule.drl")` is relative to the current working directory. – zapl Aug 14 '13 at 11:09
  • Getting error : java.lang.RuntimeException: java.io.FileNotFoundException: ..\..\inpatient\BasicAccountRule.drl (The system cannot find the path specified). Current working directory is /exim_design/src/main/java/com/up/qmhc/rules/RulesManager.java – user2652907 Aug 14 '13 at 11:21
  • That was an example, your path as to be relative to your classpath. Supposing you got a WEB application, it could be under `WEB-INF`. You could try ("rules/drl/inpatient/BasicAccountRule.drl") supposing the `resources` folder in on base of your classpath. Take a look at this question : http://stackoverflow.com/questions/4359876/how-to-load-reference-a-file-as-a-file-instance-from-the-classpath – Michael Laffargue Aug 14 '13 at 11:41