1

Hello all :) I love stackoverflow where I always find answers but this time I could not so personally asking... Its bit lengthy please go through it.

I am creating a java application where one of my resource is an exe file which I need to call in the java code. But later I would convert the whole java code to a JAR file... and I would add the JAR file and the exe file for the Setup file for installation process. So when I extract the files I want my JAR file to call the exe file while running... I am doing this all in Eclipse :)

So my doubt comes here which path I should put up in the java code... ? So that it will always call the file the exe file from the same directory where the JAR file is also present.. :)

Any help would be great :) Thank you in advance :)

Abhi
  • 1,080
  • 1
  • 7
  • 21
  • Possible duplicate of [Run .exe file from Java from file location](http://stackoverflow.com/questions/10685893/run-exe-file-from-java-from-file-location) – Exception_al Jan 17 '17 at 13:56
  • "Its bit lengthy please go through it." - Actually that question is rather short. Longer questions are not necessarily better but very short questions often lack information or display of effort and sometimes wouldn't even make it here if the problem was as easy to describe and the OP did a reasonable job searching the net first. – Thomas Jan 17 '17 at 14:01

1 Answers1

0

Assuming that you control the whole installation process; and that you also control the script that later starts a JRE to run your JAR within; my suggestion would be: simply use a property here.

In other words; your installer knows that it copied JAR and EXE to D:\example\ for example. Then just make sure that your JAR is started like:

java -jar D:\example\your.jar -D your_path=D:\example

(this is just meant as example, you would have to work that out, probably the \ in there need some special treatment for example)

Then your application can simply query for that system property "your_path" and take the value from there.

Alternatively, you could try this solution that works "pure java".

Community
  • 1
  • 1
GhostCat
  • 137,827
  • 25
  • 176
  • 248