MCPcopy Index your code
hub / github.com/HotswapProjects/HotswapAgent

github.com/HotswapProjects/HotswapAgent @RELEASE-2.0.3

Chat with this repo
repository ↗ · DeepWiki ↗ · release RELEASE-2.0.3 ↗ · + Follow
8,700 symbols 29,929 edges 1,105 files 3,315 documented · 38% updated 4mo ago2.0.4-SNAPSHOT · 2026-02-07★ 2,603106 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Hotswap Agent

<a href="https://mvnrepository.com/artifact/org.hotswapagent/hotswap-agent-core">
    <img src="https://img.shields.io/maven-central/v/org.hotswapagent/hotswap-agent-core.svg" alt="Maven">
</a>
<a href="https://travis-ci.org/HotswapProjects/HotswapAgent">
    <img src="https://travis-ci.org/HotswapProjects/HotswapAgent.svg?branch=master" alt="Build Status">
</a>
<a href="https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html">
    <img src="https://img.shields.io/badge/License-GPL%20v2-blue.svg" alt="License: GPL v2">
</a>
<a href="https://gitter.im/HotswapProjects/user">
    <img src="https://badges.gitter.im/Join%20Chat.svg" alt="Gitter">
</a>
<a href="https://twitter.com/intent/follow?screen_name=HSwapAgent">
    <img src="https://img.shields.io/twitter/follow/HSwapAgent.svg?style=social&logo=twitter" alt="follow on Twitter">
</a>

This is an overview page, please visit hotswapagent.org for more information.

Overview


Java unlimited runtime class and resource redefinition.

The primary goal of this project was to eliminate the need for the traditional "change code -> restart and wait... -> check" development cycle. Over time, this concept has evolved into a new paradigm within the Java ecosystem, allowing for real-time software development within a running application. This approach is even feasible in restricted environments, such as Docker containers.

IntelliJ - try HotswapHelper

If you're an IntelliJ user, you can simplify setup of HA and DCEVM by using the IntelliJ HotSwapHelper plugin.

Easy to start

  1. Download and Install:

    • For Java 17/21: Download the latest JBR17 or JBR21. Since these versions do not include a built-in Hotswap Agent, you will need to manually copy hotswap-agent.jar to the lib/hotswap folder. You can find the latest Hotswap Agent here. Ensure that the file in the lib/hotswap folder is named hotswap-agent.jar without any version numbers in the filename.

    • For Java 11: Use TravaJDK, which has an integrated HotswapAgent, and install it as an alternative JDK. Alternatively, TravaJDK includes an embedded HotswapAgent.

    • For Java 8: Use jdk8-dcevm along with the HotswapAgent.

  2. HotswapAgent Modes:

Starting with dcevm-11.0.9, the HotswapAgent is disabled by default. You can enable support for HotswapAgent using JVM options in one of three modes:

- `-XX:HotswapAgent=fatjar` activates the internal fatjar HotswapAgent.
- `-XX:HotswapAgent=core` activates the internal core HotswapAgent.
- `-XX:HotswapAgent=external` configures JVM support for HotswapAgent and allows the user to supply an external `hotswap-agent.jar` using the `-javaagent:<path>/hotswap-agent.jar` option.

The HotswapAgent=core mode operates without additional plugins, except for core JVM plugins, resulting in faster performance due to reduced scanning and class copying tasks. To use additional plugins, you need to configure them as Maven dependencies in your pom.xml file. On the other hand, the HotswapAgent=fatjar mode includes all plugins by default, which may slightly slow down application startup.

3.Launching:

  • Java17/21: launch your application with the options -XX:+AllowEnhancedClassRedefinition -XX:HotswapAgent=fatjar to turn on advanced hotswap (dcevm) and use Hotswap Agent fatjar release. As an alternative core or external modes can be used insted of fatjar.
  • Java11: launch your application with the options -XX:HotswapAgent=fatjar to use Hotswap Agent fatjar release.
  • Java8: launch your application with the options -XXaltjvm=dcevm -javaagent:hotswap-agent.jar to get a basic setup. Optionally you can add hotswap-agent.properties to your application to configure plugins and agent's behavior.

3.Run your application:

Start the application in debug mode, check that the agent and plugins are initialized correctly:

    HOTSWAP AGENT: 9:49:29.548 INFO (org.hotswap.agent.HotswapAgent) - Loading Hotswap agent - unlimited runtime class redefinition.
    HOTSWAP AGENT: 9:49:29.725 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [org.hotswap.agent.plugin.hotswapper.HotswapperPlugin, org.hotswap.agent.plugin.jvm.AnonymousClassPatchPlugin, org.hotswap.agent.plugin.hibernate.HibernatePlugin, org.hotswap.agent.plugin.spring.SpringPlugin, org.hotswap.agent.plugin.jetty.JettyPlugin, org.hotswap.agent.plugin.tomcat.TomcatPlugin, org.hotswap.agent.plugin.zk.ZkPlugin, org.hotswap.agent.plugin.logback.LogbackPlugin]
    ...
    HOTSWAP AGENT: 9:49:38.700 INFO (org.hotswap.agent.plugin.spring.SpringPlugin) - Spring plugin initialized - Spring core version '3.2.3.RELEASE'

4.Check redefinition

Save a changed resource and/or use the HotSwap feature of your IDE to reload changes

Plugins

Each application framework (Spring, Hibernate, Logback, ...) needs a special reloading mechanism to keep up-to-date after class redefinition (e.g. Hibernate configuration reload after new entity class is introduced). Hotswap agent works as a plugin system and is shipped preconfigured with all major framework plugins. It is easy to write your custom plugin even as part of your application.

Contribute

This project is very complex due to a lot of supported frameworks and various versions. Community contribution is mandatory to keep it alive. You can start by creating a plugin inside your application or by writing an example/integration test. There is always a need for documentation improvement :-). Thank you for any help!

What is available?

  • Enhanced Java Hotswap - change method body, add/rename a method, field, ...The only unsupported operation is changing the superclass.
    • You can use standard Java Hotswap from IDE in debug mode to reload changed class
    • or set autoHotswap property -XXaltjvm=dcevm -javaagent:PATH_TO_AGENT\hotswap-agent.jar=autoHotswap=true to reload changed classes after compilation. This setup allows even reload on a production system without a restart.
  • Automatic configuration - all local classes and resources, known to the running Java application, are automatically discovered and watched for the reload (all files on the local filesystem, not inside any JAR file).
  • Extra classpath - Need change a runtime class inside dependent JAR? Use extraClasspath property to add any directory as a classpath to watch for class files.
  • Reload resource after a change - resources from the webapp directory are usually reloaded by the application server. But what about other resources like src/main/resources? Use watchResources property to add any directory to watch for a resource change.
  • Framework support - through plugin-system, many frameworks are supported. New plugins can be easily added.
  • Fast - until the plugin is initialized, it does not consume any resources or slow down the application (see Runtime overhead for more information)

Should you have any problems or questions, ask at HotswapAgent forum.

This project is similar to JRebel. The main differences are:

  • HotswapAgent (DCEVM) supports Java8, Java11 and Java17!
  • HotswapAgent does not need any additional configuration for basic project setup.
  • JRebel is currently more mature and contains more plugins.
  • JRebel is neither open source nor free.
  • JRebel modifies bytecode of all classes on reload. You need a special IDE plugin to fix debugging.
  • HotswapAgent extraClasspath is similar to JRebel configuration
  • HotswapAgent adds watchResources configuration

Examples

See HotswapAgentExamples GitHub project. The purpose of an example application is:

  • complex automate integration tests (check various configurations before a release, see run-tests.sh script)
  • to check "real world" plugin usage during plugin development (i.e. inside a container)
  • to provide a working solution for typical application setups
  • sandbox to simulate issues for existing or new setups

Feel free to fork/branch and create an application for your setup (functional, but as simple as possible). General setups will be merged into the master.

IDE support

None needed :) Really! All changes are transparent and all you need to do is to download patch+agent and setup your application/application server. Because we use standard java hotswap behaviour, your IDE will work as expected. However, we work on IDE plugins to help with download & configuration.

Some plugins are already available:

IntelliJ HotSwapHelper

  1. Add two action next to the "Debug" button in intellij, Run with hotswap, Debug with hotswap.
  2. When click the action,will set vm parameters for you,no need to set vm parameters manually.
  3. Source code and documentation: https://github.com/gejun123456/HotSwapHelper.

Configuration

The basic configuration is set to reload classes and resources from the classpath known to the running application (classloader). If you need a different configuration, add the hotswap-agent.properties file to the classpath root (e.g. src/main/resources/hotswap-agent.properties).

Detail documentation of available properties and default values can be found in the agent properties file

Hotswap agent command-line options

Full syntax of command line options is:

-javaagent:[yourpath/]hotswap-agent.jar=[option1]=[value1],[option2]=[value2]

Hotswap agent accepts the following options:

  • autoHotswap=true - watch all .class files for change and automatically Hotswap the class in the running application (instead of running Hotswap from your IDE debugging session)
  • disablePlugin=[pluginName] - disable a plugin. Note that this will completely forbid the plugin to load (opposite to disablePlugin option in hotswap-agent.properties, which will only disable the plugin for a classloader. You can repeat this option for every plugin to disable.

Disable some plugins by vm option.

  • Add vm option -Dhotswapagent.disablePlugin=Spring,SpringBoot to disable plugins, works same as agent option disablePlugin in previous section.

How does it work?

DCEVM

Hotswap agent does the work of reloading resources and framework configuration (Spring, Hibernate, ...), but it depends on the standard Java hotswap mechanism to reload classes. Standard Java hotswap allows only method body change, which makes it practically unusable. DCEVM is a JVM (Hotspot) patch that allows almost any structural class change on hotswap (with an exception to a hierarchy change). Although hotswap agent works even with standard java, we recommend using DCEVM (and all tutorials use DCEVM as target JVM).

Hotswap Agent

Hotswap agent is a plugin container with plugin manager, plugin registry, and several agent services (e.g. to watch for class/resource change). It helps with common tasks and classloading issues. It scans the classpath for class annotated with @Plugin annotation, injects agent services, and registers reloading hooks. Runtime bytecode modification is provided by Javassist library.

Plugins

Plugins administered by Hotswap Agent are usually focused on a specific framework. For example, Spring plugin uses HA services to:

  • Modify root Spring classes to get Spring contexts and registered scan path
  • Watch for any resource change on a scan path
  • Watch for a hotswap of a class file within a scan path package
  • Reload bean definition after a change
  • ... and many others

Java frameworks plugins:

  • CXF-JAXRS (3.x) - redefine JAXRS resource after resource class redefinition, reinject instance if integrated with Spring and CDI (Weld/OWB).
  • Deltaspike (1.x,2.x) - messages, ViewConfig, repository, proxy reloading. Deltaspike scoped CDI beans reinjection.
  • ELResolver (2.x-5.x) (JuelEL, Appache Commons EL, Oracle EL 3.0)- clear ELResolver cache on class change. Support hotswap for #{...} expressions.
  • FreeMarker - clear the Apache Freemarker beans class-introspection cache on class definition change.
  • Hibernate (3.x-6.x) - Reload Hibernate configuration after entity create/change.
  • iBatis - iBatis configuration reload.
  • IDEA - support for IntelliJ IDEA development in IDEA
  • Jackson - clears jackson internal caches when class redefined.
  • Jersey1 - reload Jersey1 container after root resource or provider class definition or redefinition.
  • Jersey2 - reload Jersey2 container after root resource or provider class definition or redefinition.
  • Logback - Logback configuration reload.
  • Log4j2 - Log4j2 configuration reload.
  • Mojarra (2.x) - sup

Extension points exported contracts — how you extend this code

BeanService (Interface)
Simple service. [6 implementers]
plugin/hotswap-agent-spring-plugin/src/test/java/org/hotswap/agent/plugin/spring/testBeans/BeanService.java
HelloService (Interface)
Simple service. [95 implementers]
plugin/hotswap-agent-weld-plugin/src/test/java/org/hotswap/agent/plugin/weld/testBeans/HelloService.java
PrintTarget (Interface)
Simple Printing target - default print to output, but implement your printing target for example to support unit tests. [25 …
plugin/hotswap-agent-tutorial-plugin/src/main/java/org/hotswap/agent/tutorial/framework/PrintTarget.java
HelloService (Interface)
Simple service. [95 implementers]
plugin/hotswap-agent-owb-jakarta-plugin/src/test/java/org/hotswap/agent/plugin/owb_jakarta/testBeans/HelloService.java
HelloService (Interface)
Simple service. [95 implementers]
plugin/hotswap-agent-owb-plugin/src/test/java/org/hotswap/agent/plugin/owb/testBeans/HelloService.java
ProxyBytecodeTransformer (Interface)
Transforms the bytecode of a new proxy definition so it can be used after redefinition @author Erki Ehtla [29 implementers]
plugin/hotswap-agent-proxy-plugin/src/main/java/org/hotswap/agent/plugin/proxy/api/ProxyBytecodeTransformer.java
ClassPath (Interface)
ClassPath is an interface implemented by objects representing a class search path. ClassPool u [16 implementers]
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/ClassPath.java
InTransaction (Interface)
(no doc) [4 implementers]
plugin/hotswap-agent-hibernate-jakarta-plugin/src/test/java/org/hotswap/agent/plugin/hibernate_jakarta/HibernateJakartaPluginTest.java

Core symbols most depended-on inside this repo

append
called by 638
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/ast/ASTList.java
debug
called by 502
hotswap-agent-core/src/main/java/org/hotswap/agent/logging/AgentLogger.java
get
called by 451
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/ProxyFactory.java
getClass
called by 429
plugin/hotswap-agent-proxy-plugin/src/main/java/org/hotswap/agent/plugin/proxy/java/ProxyGenerator.java
add
called by 353
hotswap-agent-core/src/main/java/org/hotswap/agent/util/spring/collections/MultiValueMap.java
error
called by 312
hotswap-agent-core/src/main/java/org/hotswap/agent/logging/AgentLogger.java
getBean
called by 303
plugin/hotswap-agent-spring-plugin/src/main/java/org/hotswap/agent/plugin/spring/getbean/DetachableBeanHolder.java
println
called by 269
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/StackMapTable.java

Shape

Method 7,336
Class 1,236
Interface 105
Enum 23

Languages

Java100%

Modules by API surface

hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/ConstPool.java236 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/stackmap/TypeData.java140 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/CtField.java107 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/CodeIterator.java105 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/CtClassType.java102 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/compiler/CodeGen.java100 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/CtClass.java97 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/SignatureAttribute.java94 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/util/spring/collections/ConcurrentReferenceHashMap.java84 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/StackMapTable.java80 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/bytecode/Bytecode.java78 symbols
hotswap-agent-core/src/main/java/org/hotswap/agent/javassist/util/proxy/ProxyFactory.java75 symbols

For agents

$ claude mcp add HotswapAgent \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page