0

Bear with me cause I'm new to java and stackoverflow.

Problem: I have a jar that is reading a file from the environment variable of its machine(Server A). If I remote Server A and run this jar, the file reading is ok. But I needed to put this jar and a batchfile to execute it in a SHARED FOLDER to be able to access it without the need to remote Server A.

For the batchfile in the shared folder with "java -jar "%~dp0MYJAR.jar" Adding %~dp0 in front of jar name in batchfile allowed me to call the jar in shared folder. [source in link below]

Can I run a jar file from shared folder of remote system just by double clicking from my system?

But when running the jar, the jar was not able to locate the file its reading in Server A. Here's the code on reading the file.

Properties prop2 = new Properties(); 
String propFile=System.getenv("OTHERS_HOME") + "\\conf\\FILE_TO_READ.txt";

upon printing the current directory when the jar is running. When remote access to Server A i got E:\ISO_Tester. This is the correct path.

But when running in my machine from a shared folder of Server A i got C:\Windows which I think is from my local machine instead of Server A.

Community
  • 1
  • 1
Captain Catz
  • 96
  • 1
  • 12
  • What is a 'jar that is reading from the environment variable of its machine'? What does 'I remote Server A' mean? – user207421 Apr 26 '16 at 02:50
  • The Jar is in Server A and is reading file from Server A (code above). I meant remote access (Remote Desktop Connection) to Server A instead of accessing the jar via the shared folder. – Captain Catz Apr 26 '16 at 02:57

1 Answers1

0

The best part is that you should be sharing from server A the JAR file and the required files as well and write/execute the code with respect to the relative path of file

It is because the batch will not access the properties of server A, instead takes whatever available from machine where it is being executed

If you want to read more please refer this link for Get remote env vars using Windows Powershell

Harshavardhan Konakanchi
  • 4,238
  • 6
  • 36
  • 54