0

When I try to run my .jar file that is located in the project's resources folder I get an exception that says "Launch path is not accessible." I have created a bridge Objective-C file so swift will have access to NSTask interface.

My code source is:

let bundle = Bundle.main
let path = bundle.path(forResource: "/Resources/MyJar", ofType: "jar")

let task = NSTask()
task?.standardOutput = stdout
task?.standardError = stderr
task?.arguments = ["-jar", path, args]
task?.setLaunchPath("/usr/bin/java")
task?.launch()
task?.waitUntilExit()
  • What kind of test is this? Are you testing iOS or MacOS app? – drunkencheetah May 19 '22 at 06:28
  • @drunkencheetah I am testing iOS app using XCUITest framework. I am trying to run a .jar file from terminal directly from my tests. So i specify the path where Java is, where the .jar file is and argument to make my .jar start. – Temka Vibornov May 19 '22 at 14:29
  • I don't think this will work, when you run tests on iOS the test runner lives on the device/simulator and does not have direct access to the host terminal. What I use in my current project is [SBTUITestTunnelHost](https://github.com/Subito-it/SBTUITestTunnelHost) which allows me to execute shell commands on the host and send push notifications with 'xcrun simctl' for example. – drunkencheetah May 20 '22 at 08:02
  • Thanks alot. Ill try it out and let you know if it helped – Temka Vibornov May 20 '22 at 10:24

0 Answers0