{"id":15584920,"url":"https://github.com/swiftlang/swift-java","last_synced_at":"2026-04-09T03:01:12.985Z","repository":{"id":257807443,"uuid":"862476999","full_name":"swiftlang/swift-java","owner":"swiftlang","description":"Java interopability support for Swift","archived":false,"fork":false,"pushed_at":"2026-04-02T08:41:42.000Z","size":2998,"stargazers_count":1195,"open_issues_count":121,"forks_count":99,"subscribers_count":27,"default_branch":"main","last_synced_at":"2026-04-03T00:41:44.125Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/swiftlang/swift-java/main/documentation/swiftjavadocumentation","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swiftlang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-09-24T17:01:00.000Z","updated_at":"2026-04-02T08:41:47.000Z","dependencies_parsed_at":null,"dependency_job_id":"86a411a9-f790-4512-a2cb-25ce3f14994d","html_url":"https://github.com/swiftlang/swift-java","commit_stats":null,"previous_names":["swiftlang/swift-java"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/swiftlang/swift-java","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftlang%2Fswift-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftlang%2Fswift-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftlang%2Fswift-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftlang%2Fswift-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swiftlang","download_url":"https://codeload.github.com/swiftlang/swift-java/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swiftlang%2Fswift-java/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31583290,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-08T14:31:17.711Z","status":"online","status_checked_at":"2026-04-09T02:00:06.848Z","response_time":112,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-02T21:00:30.489Z","updated_at":"2026-04-09T03:01:12.935Z","avatar_url":"https://github.com/swiftlang.png","language":"Swift","funding_links":[],"categories":["HarmonyOS","Swift","互操作"],"sub_categories":["Windows Manager","文件同步"],"readme":"# Swift Java Interoperability Tools and Libraries\n\nThis project contains tools and libraries that facilitate **Swift \u0026 Java Interoperability**.\n\n- Swift library (`SwiftJava`) and bindings generator that allows a Swift program to make use of Java libraries by wrapping Java classes in corresponding Swift types, allowing Swift to directly call any wrapped Java API.\n- The `swift-java` tool which offers automated ways to import or \"extract\" bindings to sources or libraries in either language. The results are bindings for Swift or Java.\n\n## Introduction\n\nIf you'd like to check out a quick introduction to Swift \u0026 Java interoperability, you may be interested in this presentation from WWDC25: [WWDC25: Explore Swift and Java interoperability](https://www.youtube.com/watch?v=QSHO-GUGidA).\n\nWhile we work on more quickstarts and documentation, please refer to the Sample projects located in [Samples/](Samples/) that showcase the various ways you can use swift-java in your Swift or Java projects.\n\n## Dependencies\n\n### Required JDK versions\n\nNote that this project consists of multiple modules which currently have different Swift and Java runtime requirements.\n\nYou'll need to install the necessary JDK version locally. On macOS for example, you can install the JDK with [homebrew](https://brew.sh) using:\n\n```bash\n$ brew install openjdk\n# and create a symlink into /Library/Java/JavaVirtualMachines\n$ sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk\n\n# or if you have a distribution as cask it will be installed into /Library/Java/JavaVirtualMachines\n$ brew install --cask corretto\n```\n\nAlternatively, you can use a JDK manager like [sdkman](https://sdkman.io/install/) and set your `JAVA_HOME` environment variable:\n\n```bash\n$ export JAVA_HOME=\"$(sdk home java current)\"\n```\n\nE.g sdkman install command:\n\n```bash\nsdk install java 25.0.1-amzn\n```\n\n## Self-publish supporting Java libraries\n\nSwift-java relies on supporting libraries that are under active development and not yet published to Maven Central. To use the project, you'll need to self-publish these libraries locally so your Java project can depend on them.\n\nTo publish the libraries to your local maven repository (`$HOME/.m2`), you can run:\n\n```\n// in swift-java/\n./gradlew publishToMavenLocal\n```\n\nTo consume these libraries in your Java project built using Gradle, you can then include the local repository in the repositories to resolve dependencies from:\n\n```\nrepositories {\n    mavenLocal()\n    mavenCentral()\n}\n```\n\nWe anticipate simplifying this in the future.\n\n## SwiftJava macros\n\nSwiftJava is a Swift library offering macros which simplify writing JNI code \"by hand\" but also calling Java code from Swift.\n\nIt is possible to generate Swift bindings to Java libraries using SwiftJava by using the `swift-java wrap-java` command.\n\nRequired language/runtime versions:\n- **JDK 17+**, any recent JDK installation should be sufficient, as only general reflection and JNI APIs are used by this integratio\n- **Swift 6.2.x**, because the library uses modern Swift macros\n\n**swift-java jextract** \n\nIs a source generator which will **generate Java bindings to existing Swift libraries**. \nIts inputs are Swift sources or packages, and outputs are generated Swift and Java code necessary to call these functions efficiently from Java.\n\n## swift-java jextract --mode=ffm (default)\n\nThis mode provides the most flexibility and performance, and allows to decrease the amount of data being copied between Swift and Java.\nThis does require the use of the relatively recent [JEP-454: Foreign Function \u0026 Memory API](https://openjdk.org/jeps/454), which is only available since JDK22, and will become part of JDK LTS releases with JDK 25 (depending on your JDK vendor).\n\nThis is the primary way we envision calling Swift code from server-side Java libraries and applications.\n\nRequired language/runtime versions:\n- **Swift 6.2**, because of dependence on rich swift interface files\n- **JDK 25+**\n  - We are validating the implementation using the currently supported non-LTE release, which at present means JDK-25.\n\n## swift-java jextract --mode=jni\n\nIn this mode, the generated sources will use the legacy JNI approach to calling native code.\n\nThis mode is more limited in some performance and flexibility that it can offer, however it is the most compatible, since even very old JVM's as well as even Android systems can be supported by this mode.\nWe recommend this mode when FFM is not available, or wide ranging deployment compatibility is your priority. When performance is paramaunt, we recommend the FFM mode instead.\n\nRequired language/runtime versions:\n- **Swift 6.2**, because of dependence on rich swift interface files  \n- **Java 7+**, including \n\n\n## Development and Testing\n\nThis project contains multiple builds, living side by side together.\n\nYou will need to have:\n- Swift (6.2.x+)\n- Java (25+ for FFM, even though we support lower JDK targets)\n- Gradle (installed by \"Gradle wrapper\" automatically when you run gradle through `./gradlew`)\n\n### Preparing your environment\n\nInstall **Swift**, the easiest way to do this is to use **Swiftly**: [swift.org/install/](https://www.swift.org/install/).\nThis should automatically install a recent Swift, but you can always make sure by running:\n\n```bash\nswiftly install 6.2 --use\n```\n\nInstall a recent enough Java distribution. We validate this project using Corretto so you can choose to use that as well,\nhowever any recent enough Java distribution should work correctly. You can use sdkman to install Java:\n\n```bash\n# Install sdkman from: https://sdkman.io\ncurl -s \"https://get.sdkman.io\" | bash\nsdk install java 17.0.15-amzn\nsdk install java 25.0.1-amzn\n\nsdk use java 25.0.1-amzn\n```\n\nThe use of JDK 25 is required to build the project, even though the libraries being published may target lower Java versions.\n\n❗️ Please make sure to `export JAVA_HOME` such that swift-java can find the necessary java libraries!\nWhen using sdkman the easiest way to export JAVA_HOME is to export the \"current\" used JDK's home, like this:\n\n```bash\nexport JAVA_HOME=\"$(sdk home java current)\"\n```\n\n### Testing your changes \n\nMany tests, including source generation tests, are written in Swift and you can execute them all by running the \nswift package manager test command:\n\n```bash\n\u003e swift test\n```\n\nWhen adding tests in `Tests/...` targets, you can run these tests (or filter a specific test using `swift test --filter type-or-method-name`).\n\nSome tests are implemented in Java and therefore need to be executed using Gradle.\nPlease always use the gradle wrapper (`./gradlew`) to make sure to use the appropriate Gradle version\n\n```bash\n\u003e ./gradlew test\n```\n\n\u003e Tip: A lot of the **runtime tests** for code relying on `jextract` are **located in sample apps**, \n\u003e so if you need to runtime test any code relying on source generation steps of jextract, consider adding the tests\n\u003e to an appropriate Sample. These tests are also executed in CI (which you can check in the `ci-validate.sh` script \n\u003e contained in every sample repository).\n\n### Sample apps \u0026 tests\n\nSample apps are located in the `Samples/` directory, and they showcase full \"roundtrip\" usage of the library and/or tools.\n\nSamples are build by default by Gradle. Building samples can be skipped by appending the flag `-PskipSamples=true` to a gradle command.\n\n#### SwiftJava (Swift -\u003e Java)\n\nTo run a simple app showcasing a Swift process calling into a Java library you can run: \n\n```bash\ncd Samples/SwiftJavaExtractFFMSampleApp\n./ci-validate.sh # which is just `swift build` and a `java -cp ...` invocation of the compiled program\n```\n\n#### jextract (Java -\u003e Swift)\n\nTo run a simple example app showcasing the jextract (Java calling Swift) approach you can:\n\n```bash\n./gradlew Samples:SwiftJavaExtractFFMSampleApp:run\n```\n\nThis will also generate the necessary sources (by invoking jextract, extracting the `Sources/ExampleSwiftLibrary`) \nand generating Java sources in `src/generated/java`.\n\n#### Other sample apps\n\nPlease refer to the [Samples](Samples) directory for more sample apps which showcase the various usage modes of swift-java.\n\n## Benchmarks\n\nYou can run Swift [ordo-one/package-benchmark](https://github.com/ordo-one/package-benchmark) and OpenJDK [JMH](https://github.com/openjdk/jmh) benchmarks in this project.\n\nSwift benchmarks are located under `Benchmarks/` and JMH benchmarks are currently part of the SwiftKit sample project: `Samples/SwiftJavaExtractFFMSampleApp/src/jmh` because they depend on generated sources from the sample.\n\n### Swift benchmarks\n\nTo run **Swift benchmarks** you can:\n\n```bash\ncd Benchmarks\nswift package benchmark\n```\n\n### Java benchmarks\n\nIn order to run JMH benchmarks you can:\n\n```bash\ncd Samples/SwiftJavaExtractFFMSampleApp\n./gradlew jmh\n```\n\nPlease read documentation of both performance testing tools and understand that results must be interpreted and not just taken at face value. Benchmarking is tricky and environment sensitive task, so please be careful when constructing and reading benchmarks and their results. If in doubt, please reach out on the forums.\n\n## User Guide\n\nMore details about the project can be found in [docc](https://www.swift.org/documentation/docc/) documentation.\n\nTo view the rendered docc documentation you can use the docc preview command:\n\n```bash\nxcrun docc preview Sources/SwiftJavaDocumentation/Documentation.docc\n\n# OR SwiftJava to view SwiftJava documentation:\n# xcrun docc preview Sources/SwiftJava/Documentation.docc\n\n# ========================================\n# Starting Local Preview Server\n#\t Address: http://localhost:8080/documentation/documentation\n# ========================================\n# Monitoring /Users/ktoso/code/swift-java/Sources/SwiftJavaDocumentation/Documentation.docc for changes...\n\n```\n\n## Project Status\n\n**This project is under active development. We welcome feedback about any issues you encounter.** \n\nThere is no guarantee about API stability until the project reaches a 1.0 release.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftlang%2Fswift-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswiftlang%2Fswift-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswiftlang%2Fswift-java/lists"}