Runtime Modification of Project Properties Using Java Agent Attachment

This article explains how to dynamically modify a Java project's properties at runtime without restarting the JVM by attaching a custom Java agent, configuring Maven dependencies, and using JConsole or Telnet for property updates.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
Runtime Modification of Project Properties Using Java Agent Attachment

The article introduces a method for dynamically configuring properties in a running Java application, useful for legacy projects that have not adopted Apollo and need to change JVM-level configuration without a restart.

Attaching a Java Agent

First, identify the target JVM process ID using jps and inject the agent JAR with the following command:

java -cp /Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/lib/tools.jar:dynamic-agent-0.0.1-SNAPSHOT.jar com.agent.StartApp LoadAgent 79056 /Users/steven/temp/dynamic-agent-0.0.1-SNAPSHOT.jar

The tools.jar provides the VirtualMachine class required for attachment. The arguments are: dynamic-agent-0.0.1-SNAPSHOT.jar – the built agent JAR. LoadAgent – the class to invoke. 79023 – the target JVM process ID. /Users/steven/temp/dynamic-agent-0.0.1-SNAPSHOT.jar – path to the agent JAR.

Local Maven Configuration

To compile the project, add a system‑scoped dependency on tools.jar with an absolute path (adjust for Windows if needed):

<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.7</version>
<scope>system</scope><systemPath>/Library/Java/JavaVirtualMachines/jdk1.8.0_181.jdk/Contents/Home/lib/tools.jar</systemPath>
</dependency>

Important Notes

If the production JDK version is lower than the JDK used to build the agent, downgrade the agent’s JDK accordingly.

The agent can modify system properties only, and supports two update mechanisms: JConsole interaction and Telnet commands.

Using the Agent

After attachment, the agent registers an MBean ( com.steven:type=NewBiAgentManagement) that exposes dynamic property controls. The console UI (shown in the screenshots) displays success indicators and a JSON console linked to the running application.

Agent UI
Agent UI

Configuration steps are illustrated with screenshots for both the UI and Telnet interaction.

Repository

The complete project, including the agent source and usage instructions, is available at https://gitee.com/coderunning/dynamic-property .

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

javaJVMDynamic ConfigurationmavenJava Agent
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.