0

I made a database and java application which autoupdates the front end of a database. The only issue is, the code I use to run the jar file references the java bin file location. There are different java versions in our environment, so the path can't be hard coded.

How can I get the computers current jre/bin location?

Private Function RunJar()
    ChDir LocationToJar
    Shell """C:\Program Files\Java\jre7\bin\java"" -jar myprog.jar"
End Function
DrakeWalker
  • 47
  • 1
  • 6
  • 2
    Why use a Java application to update your Access application? In doing so, you've introduced **two** major dependencies just to run your Access - an Access installation (whether as a standalone Access runtime or as a part of Office) _and_ the Java runtime. Don't you think it'd be less demanding on your users if the autoupdater was delivered in some existing runtime... such as a 2nd Access file? Or a native Windows EXE? Heck, even a .NET executable avoids the problem because in those case they are using Windows' provided runtime libraries. Java implies you must provide it yourself. – this Nov 02 '18 at 15:57
  • I could do it in C++ for the the exe, however, a java version is REQUIRED on all of our business machines. So in this case, I decided to use java. Depending on if I get any useful answers, I just might use C++. – DrakeWalker Nov 02 '18 at 17:27

2 Answers2

0

You have just to execute the commande where java and get the output as java jre path

dim jrePath as string 
jrePath = redirect("cmd","/c dir")
jrePath = redirect("where java","")

Source get jre path: https://superuser.com/questions/543810/where-is-java-jre-path-specified-in-windows-7

Source #2 get jre path: https://social.msdn.microsoft.com/Forums/en-US/c6165d7e-e466-4582-ae51-48bd51b01983/detect-java-bin-folder-automatically-through-vba?forum=isvvba

Source VBA code: Capture output value from a shell command in VBA?

Good luck.

AbA2L
  • 100
  • 7
  • 1
    where is 'redirect' defined? –  Nov 02 '18 at 15:36
  • It's defined in code for 'Source VBA code', but that just seems like too much code for something so simple. There has to be another way. Source #2 could lead to a lot of issues... Edit: There was another answer below that one, which seems simpler. Going to give it a try. – DrakeWalker Nov 02 '18 at 15:49
  • I used Brian Burns code in the 'Source VBA code' link, but I'm curious if I can hide the cmd window as it pops up for a split second. – DrakeWalker Nov 02 '18 at 17:29
  • https://stackoverflow.com/questions/23557720/execute-batch-file-without-command-line-visible –  Nov 07 '18 at 19:56
0

I ended up not needing to use the direct path, as just using 'Java' in it's place worked.

I'm not sure if this is due to 'where java' always replying with ProgramData\Oracle\Java\javapath\Java.exe' in my environment.

DrakeWalker
  • 47
  • 1
  • 6