Java Debugging
Raftt supports interactive debugging for Java (and other JVM-based languages) using JetBrains IntelliJ. Support for VS Code is coming soon!
To debug with Raftt, you must first install Raftt's IDE plugin. See here for installation instructions.
Configuration
To configure Java debugging you need to define two things -
- Where and when to compile your Java app
- Add a builder container to the workload
- Define a before launch task
- Create a run/debug configuration
Add a builder container
The best way to let your env compile the Java app without modifying your application container is by adding a builder container to the pod. This can be easily defined in your .raftt
file. Here you can see the configuration for adding a builder container to the ads
service of our sample project -
ads = resources.deployments["ads"]
# Define the container and add it to the workload
builder = Container(yaml="""
name: builder
image: openjdk:latest
workingDir: /src
""")
ads.spec.template.spec.containers.append(builder)
# Mount the source code and the compiled artifact folder to
# both the application container and the builder container
ads_out = volume("ads-out")
ads.mount(repo_root.subpath("src/adservice/src"), "/src", container="builder")
ads.mount(repo_root.subpath("src/adservice/src"), "/src")
ads.mount(ads_out, "/tmp/out", container="builder")
ads.mount(ads_out, "/app", init_on_rebuild=True)
Make sure that the container has an image that can actually compile your JAR. For example, you'll need a different image to build JARs from Kotlin or Scala.
Create a run/debug configuration
To debug with Raftt, start by defining a run/debug configuration of the type JAR Application
(that's true even if you use build tools like Gradle or Maven). It should be configured like a standard JAR application run/debug config, with the path in the debugged workload in the path to JAR
attribute. Then, add a single env var called RAFTT_WORKLOAD
stating the workload to debug.
Here you can see the configuration for the ads
service of our sample project -
Debugging a sidecar container
To debug a sidecar container, add an additional env var - RAFTT_CONTAINER
, whose value is the debugged container name. If not stated, the selected container is the workload's main container - either the one annotated as default, or if no container is annotated - the first one in the manifest.
Create a before launch task
To recompile your code before every run/debug session, you need to define a before launch task in you debug configuration. Create a task of the type Run on Raftt Workload
and define what build script to run and where -
Make sure to modify the command according to your language (e.g., Java, Kotlin, etc.) and build system (e.g. Gradle, Maven, etc.)
To easily share your run/debug configuration with the rest of the team, mark the "store as project file" checkbox and commit the new file, typically located under .run
, to the repo.