To try out Hotswap-agent and DCEVM with Clojure, so that we can reload freshly compiled Java classes without restarting the REPL.
This is useful when developing mixed codebases with both Clojure and Java: We might have a REPL running and then we edit a java
file that we compile using lein javac
. Normally, we would have to restart the repl in order for those changes to be visible,
but with DCEVM and hotswap-agent, the recompile class file is automatically imported without having to restart the REPL.
- Download and unpack TravaOpenJDK from this page: https://github.com/TravaOpenJDK/trava-jdk-11-dcevm/releases/tag/dcevm-11.0.5%2B4
- Define
JAVA_HOME
to point at the unpacked directory. - Launch the REPL and load the namespace
hotswap-dcevm-clojure-demo.core
a few times. - Edit the file
src/java/Mjao.java
and compile it usinglein javac
. - Load the file
hotswap-dcevm-clojure-demo.core
again. - Repeat step 4 and 5...
Mjao result (3): 13
Mjao result (3): 13
Mjao result (3): 13
HOTSWAP AGENT: 13:15:53.645 RELOAD (org.hotswap.agent.config.PluginManager) - Reloading classes [Mjao] (autoHotswap)
Mjao result (3): 103
Mjao result (3): 103
HOTSWAP AGENT: 13:16:08.070 RELOAD (org.hotswap.agent.config.PluginManager) - Reloading classes [Mjao] (autoHotswap)
Mjao result (3): 10003
user>
To have automatic class reloading in the REPL, these two things are needed:
- A
resources/hotswap-agent.properties
file containing the lineautoHotswap=true
JAVA_HOME
environment variable pointing at the JDK found here, or newer.
- Main page of the project: http://hotswapagent.org/
- Instructions for getting the JDK: http://hotswapagent.org/mydoc_quickstart-jdk11.html
- About the Hotswapper plugin: http://hotswapagent.org/mydoc_plugin_hotswapper.html
- Example file of
hotswap-agent.properties
: https://github.com/HotswapProjects/HotswapAgent/blob/master/hotswap-agent-core/src/main/resources/hotswap-agent.properties
Copyright © 2019 Jonas Östlund
This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.