Jar.swift is created and maintaned with ❥ by Sascha Muellner.
This is a Swift package with support for macOS that allows to start Java Jar's with the default or a custom JVM.
The latest version of Jar requires:
- Swift 5+
- macOS 10.12+
- Xcode 11+
Using SPM add the following to your dependencies
'Jar', 'main', 'https://github.com/SwiftPackageRepository/Jar.swift.git'
For running a remote Jar the only requirement is creating a Jar reference with the origin of the Jar and the locale name for the cache. After creating a Java runtime reference the Jar can be just "executed".
let jar = Jar(origin: URL(string: "https://domain.com/your.jar"), filename: "your.jar")
let java = Java()
let (result, error) = java.run(jar: jar, args: [])
or more complete for running the HelloWorld.jar:
import Foundation
import Jar
struct HelloWorld {
static func run() {
let url = URL(string: "https://github.com/slaminatl/Helloworld/raw/master/out/artifacts/HelloWorld_jar/HelloWorld.jar")!
let jar = Jar(origin: url, filename: "helloworld.jar")
let java = Java()
let (result, error) = java.run(jar: jar, args: [])
if let result = result {
print(result)
} else if let error = error {
print(error.localizedDescription)
}
}
}