Portals.Java (portals_java v0.1.0)

Copy Markdown View Source

Run Java workers under Portals.

This package bundles the dependency-free Java worker SDK as a prebuilt portals.jar (compiled for Java 17) and puts it on the worker's classpath ahead of your own classes — nothing is fetched from Maven.

Compile your handlers against the same jar (javac -cp "$(mix portals.sdk_path java)" ...), then:

children = [
  {Portals.Pool,
   Portals.Java.worker_opts(
     main: "com.example.RunWorker",
     classpath: [Application.app_dir(:my_app, "priv/java/classes")],
     name: MyApp.Java,
     size: 2
   )}
]

See the Java guide for a full walkthrough.

Summary

Functions

Absolute path to the bundled portals.jar.

Functions

sdk_path()

Absolute path to the bundled portals.jar.

worker_opts(opts)

Build Portals.start_worker/1 / Portals.start_pool/1 options for a Java worker.

Options

  • :main (required) — the fully qualified class whose main runs new Worker()...run(args).
  • :classpath — your own classpath entries (directories or jars), appended after portals.jar. Defaults to [].
  • :java — the java launcher, as a name looked up on PATH or a path. Defaults to "java".
  • :java_args — JVM flags placed before -cp, e.g. ["-Xmx512m"].
  • :args — arguments passed to main. Portals appends the socket path after these, as the last argument.
  • :env — extra {name, value} environment entries; these win over the ones set here.

Every other option is passed through unchanged.