Define a JVM Executable

Problem

You need to specify a Scala or Java binary target that you can compile and/or run directly.

If you need to specify a Scala or Java library target, see Create a New Scala or Java Library Target.

Solution

Create a jvm_binary target definition for your project that specifies which scala_library or java_library target will be included in the binary (you can also include several).

Discussion

In any jvm_binary target you must specify the following:

  • A name for the target
  • A basename that will be used as the basis of the filename if you bundle the target using a jvm_app target
  • The main function which serves as the executable's entry point.
  • A list of dependencies that must include at least one scala_library or java_library target. More info can be found in Add a Dependency from Source.
  • A list of file bundles for use as static assets (optional). More info can be found in Specify a File Bundle.

Here's an example jvm_binary definition:

jvm_binary(
  name='bin',
  basename='myproject-bin',
  main='com.acme.myproject.Main',
  dependencies=[
    'src/java/com/myorg/myproject/server',
    'src/java/com/myorg/myproject/analytics',
  ],
  bundles=[
    bundle(fileset=['assets/*']),
  ]
)

See Also

Generated by publish_docs from dist/markdown/html/src/docs/common_tasks/jvm_binary.html 2022-12-03T01:08:59.562143