如何在不停止节点的情况下热更新CorDapp并实现部署与运行解耦?
Great question—this is a super common requirement when working with Corda, especially when you want to keep your network running smoothly while iterating on your CorDapp code. Let’s walk through exactly how to do this:
First, you’ll need to build a fresh Jar of your modified CorDapp. The exact command depends on your build tool, but here’s the standard approach for the most common tools:
Gradle: Run the following command from your project root. This will build all modules (contracts, workflows, etc.) and output the Jar files in each module’s
build/libsdirectory../gradlew jarPro tip: Make sure your
build.gradlefiles mark Corda core dependencies (likecorda-core,corda-node-api) asprovidedorruntimeOnly—this avoids bundling these into your Jar since the node already has them installed.Maven: Use this command to build and package your CorDapp. The Jars will end up in each module’s
targetdirectory.mvn clean packageDouble-check your
pom.xmlto exclude Corda core dependencies from the final Jar to keep it lightweight and avoid conflicts.
Corda (starting from version 4.x) supports hot reloading of CorDapps, so you don’t need to shut down your node. Here’s the step-by-step process:
Locate the node’s Cordapps directory: By default, this is the
cordappsfolder in your node’s root directory. If you’ve customized your node configuration, check thenode.conffile for thecordappsDirsetting to find the correct path.Replace or add the Jar:
- For an update: Delete the old version of your CorDapp Jar from the
cordappsdirectory, then copy your newly built Jar into it. - For a new deployment: Simply copy the new Jar into the
cordappsdirectory.
- For an update: Delete the old version of your CorDapp Jar from the
Trigger the node to reload CorDapps:
- Using the Node Shell: If you have the node shell open, run this command:
run reloadCordapps - Using RPC: If you’re interacting with the node via an RPC client, call the
reloadCordapps()method on theNodeRPCConnectioninstance.
- Using the Node Shell: If you have the node shell open, run this command:
Verify the deployment:
- Run this command in the node shell to confirm the new CorDapp is loaded (check the version number to ensure it’s the updated one):
run listCordapps - Test your updated flows/states/contracts to make sure they work as expected—this will catch any compatibility issues early.
- Run this command in the node shell to confirm the new CorDapp is loaded (check the version number to ensure it’s the updated one):
- State Evolution: If you modified the structure of a state, make sure you follow Corda’s state evolution rules (like adding new fields with default values, using
@BelongsToContractcorrectly). Failing to do this can break existing states stored on the node. - Contract Updates: Changing contract logic requires extra care—ensure old transactions can still be validated by the new contract, or use contract versioning to maintain backward compatibility.
- Running Flows: Avoid replacing the Jar while flows that depend on it are still running. Wait for active flows to complete first to prevent runtime errors.
- Check Logs: After reloading, check the node’s logs (usually in the
logsdirectory) to make sure there are no loading errors or dependency conflicts.
内容的提问来源于stack exchange,提问作者SrikanthVarma A

