hotswapprojects / hotswapagentexamples Goto Github PK
View Code? Open in Web Editor NEWExample applications for HotswapAgent plugins
License: GNU General Public License v2.0
Example applications for HotswapAgent plugins
License: GNU General Public License v2.0
Hi there.
I'm investigating writing a custom plugin to allow hot reload of the Javalin framework. For now, I'm not trying to get anything production ready, just get my head round what is needed, but I'm struggling to get the agent to call my plugin even though it is initialised.
I have a top level object call App which has a method call "reload". For now, all I want to do is make it so that if any class is changed, the reload method is called.
Okay. So I have a top level kotlin object called App
package io.javalin.hotswap
import io.javalin.Javalin
object App {
private val server = Javalin.create()
fun start(){
server.start(7777)
server.get("/",TestClass::home)
}
fun stop(){
server.stop()
}
fun reload(){
stop()
start()
}
}
fun main(args: Array<String>){
App.start()
}
that makes reference to another object TestClass
package io.javalin.hotswap
import io.javalin.http.Context
object TestClass {
fun home(ctx: Context){
ctx.result("Hi there")
}
}
What I want is for a change to TestClass (or any other class) to cause the reload method on App to be called
I therefore implemented the following Plugin
@Plugin(
name = "Reload Plugin",
description = "Testing reload plugin",
testedVersions = ["unknown"]
)
class ReloadPlugin {
@OnClassLoadEvent(classNameRegexp = ".*")
fun onClassReloaded() {
logger.info("one or more classes reloaded")
}
companion object {
val logger = AgentLogger.getLogger(ReloadPlugin::class.java)
@JvmStatic
@OnClassLoadEvent(classNameRegexp = "io.javalin.hotswap.App")
fun onApplicationStart() {
logger.info("reload plugin initialised")
PluginManagerInvoker.buildInitializePlugin(ReloadPlugin::class.java)
}
}
}
When I run the app in debug mode, I see the following
HOTSWAP AGENT: 11:59:40.349 DEBUG (org.hotswap.agent.annotation.handler.OnClassLoadedHandler) - Init for method public static final void io.javalin.hotswap.ReloadPlugin.onApplicationStart()
HOTSWAP AGENT: 11:59:40.350 DEBUG (org.hotswap.agent.util.HotswapTransformer) - Registering transformer for class regexp 'io.javalin.hotswap.App'.
HOTSWAP AGENT: 11:59:40.351 DEBUG (org.hotswap.agent.config.PluginRegistry) - Plugin registered class io.javalin.hotswap.ReloadPlugin.
HOTSWAP AGENT: 11:59:40.351 INFO (org.hotswap.agent.config.PluginRegistry) - Discovered plugins: [Reload Plugin]
so it correctly finds my plugin. Then, a little later I see
HOTSWAP AGENT: 11:59:40.428 INFO (io.javalin.hotswap.ReloadPlugin) - reload plugin initialised
so it is also initialising my plugin. However, when I change the TestClass and compile I see
HOTSWAP AGENT: 12:00:14.067 DEBUG (org.hotswap.agent.plugin.jvm.ClassInitPlugin) - Adding $$ha$clinit to class: io.javalin.hotswap.TestClass
HOTSWAP AGENT: 12:00:14.077 DEBUG (org.hotswap.agent.plugin.jvm.ClassInitPlugin) - Skipping old field INSTANCE
HOTSWAP AGENT: 12:00:14.107 DEBUG (org.hotswap.agent.plugin.jdk.JdkPlugin) - Flushing io.javalin.hotswap.TestClass from com.sun.beans.introspect.ClassInfo cache
HOTSWAP AGENT: 12:00:14.110 DEBUG (org.hotswap.agent.plugin.jdk.JdkPlugin) - Flushing io.javalin.hotswap.TestClass from introspector
HOTSWAP AGENT: 12:00:14.112 TRACE (org.hotswap.agent.plugin.jdk.JdkPlugin) - Removing class from declaredMethodCache.
HOTSWAP AGENT: 12:00:14.112 DEBUG (org.hotswap.agent.plugin.jdk.JdkPlugin) - Flushing io.javalin.hotswap.TestClass from ObjectStreamClass caches
so it is indeed redefining the TestClass but my @OnClassLoadEvent is not being called despite having a regexp of ".*".
I tried to follow the custom plugin example but it was using a very old version and referring to annotations which did not exist any more, and when I tried to run a copy to understand it better, it said it was for Java version 5!
If anyone could explain what I'm doing wrong, that would be much appreciated
Have any spring/(jetty or tomcat) projects that use gradle rather than maven for building?
I exported the two settings variable like this :
export MAVEN_OPTS='-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000 -Xms256m -Xmx1048m -XX:MaxPermSize=512m -XX:NewRatio=6 -XX:+CMSClassUnloadingEnabled -XX:+CMSPermGenSweepingEnabled' -XXaltjvm=dcevm -javaagent:e:\HotswapAgent.jar
and maven gave not a valid identifier
error. How to use it in maven webapps ?
mvn tomcat7:run
Hi there.
Am working on a custom plugin for reloading Javalin on any class or resource change. I have the class reloading part working and the resource reloading works, but has some quirks or areas I don't understand
Finally, thanks very much for what is a fantastically useful piece of code. With the reload plugin implemented, the application restarts in 10ms which makes for a much nicer development workflow
Create robust automate tests to run before release.
Hi, this feels like a stupid question but I can't do anything with this project. Maven complains about the project structure. See the following output after I cloned the project:
(Maven 3.3.3 on Java 7)
C:\dev\HotswapAgentExamples>mvn install
[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[WARNING] 'parent.relativePath' of POM org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:unknown-version
points at org.hotswap.agent:hotswap-ag
ent-examples-aggregator instead of org.hotswap.agent:hotswap-agent-parent, please verify your project structure @ line 5
, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version]
: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at
wrong local POM @ line 5, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.examples:plain-java:[unknown-version](C:devHotswapAgentExample
splain-javapom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org.hotswap.agent:hotswap
-agent-parent, please verify your project structure @ line 7, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.examples:plain-java:[unknown-version]: Could not find artifact org.hot
swap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, column
13
[WARNING] 'parent.relativePath' of POM org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:unknown-version
points at org.hotswap.agent:hotswap-ag
ent-examples-aggregator instead of org.hotswap.agent:hotswap-agent-parent, please verify your project structure @ org.ho
tswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\HotswapAgentExamples\hotswap-ag
ent-examples-servlet-parent\pom.xml, line 5, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version]
: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at
wrong local POM @ org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\Hotswap
AgentExamples\hotswap-agent-examples-servlet-parent\pom.xml, line 5, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.plugin.examples:custom-plugin:[unknown-version](C:devHotswapAg
entExamplescustom-pluginpom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org.hotswap.
agent:hotswap-agent-parent, please verify your project structure @ line 7, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.plugin.examples:custom-plugin:[unknown-version]: Could not find artifa
ct org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line
7, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:unknown-version
points at org.hotswap.agent:hotswap-ag
ent-examples-aggregator instead of org.hotswap.agent:hotswap-agent-parent, please verify your project structure @ org.ho
tswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\HotswapAgentExamples\hotswap-ag
ent-examples-servlet-parent\pom.xml, line 5, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version]
: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at
wrong local POM @ org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\Hotswap
AgentExamples\hotswap-agent-examples-servlet-parent\pom.xml, line 5, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.examples:seam-hibernate-jsf:[unknown-version](C:devHotswapAgen
tExamplesseam-hibernate-jsfpom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org.hotsw
ap.agent:hotswap-agent-parent, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.examples:seam-hibernate-jsf:[unknown-version]: Failure to find org.hot
swap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT in http://snapshots.jboss.org/maven2/ was cached in the local reposit
ory, resolution will not be reattempted until the update interval of snapshots.jboss.org has elapsed or updates are forc
ed and 'parent.relativePath' points at wrong local POM @ line 6, column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.examples:cdi-hibernate-jsf:[unknown-version](C:devHotswapAgent
Examplescdi-hibernate-jsfpom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org.hotswap
.agent:hotswap-agent-parent, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.examples:cdi-hibernate-jsf:[unknown-version]: Could not find artifact
org.hotswap.agent:hotswap-agent-parent:pom:0.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 6,
column 13
[WARNING] 'parent.relativePath' of POM org.hotswap.examples:ejb-cdi-hibernate-jsf:[unknown-version](C:devHotswapA
gentExamplesejb-cdi-hibernate-jsfpom.xml) points at org.hotswap.agent:hotswap-agent-examples-aggregator instead of org
.hotswap.agent:hotswap-agent-parent, please verify your project structure @ line 6, column 13
[FATAL] Non-resolvable parent POM for org.hotswap.examples:ejb-cdi-hibernate-jsf:[unknown-version]: Failure to find org.
hotswap.agent:hotswap-agent-parent:pom:0.3.0-SNAPSHOT in https://repository.jboss.org/nexus/content/groups/public/ was c
ached in the local repository, resolution will not be reattempted until the update interval of JBoss Repository has elap
sed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 6, column 13
@
[ERROR] The build could not read 8 projects -> [Help 1]
[ERROR]
[ERROR] The project org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version](C:devHot
swapAgentExampleshotswap-agent-examples-servlet-parentpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-vers
ion]: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points
at wrong local POM @ line 5, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:plain-java:[unknown-version](C:devHotswapAgentExamplesplain-javapom.
xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.examples:plain-java:[unknown-version]: Could not find artifact org
.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line 7, col
umn 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:plain-servlet:[unknown-version](C:devHotswapAgentExamplesplain-servle
tpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-vers
ion]: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points
at wrong local POM @ org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\Hot
swapAgentExamples\hotswap-agent-examples-servlet-parent\pom.xml, line 5, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.plugin.examples:custom-plugin:[unknown-version](C:devHotswapAgentExamplescusto
m-pluginpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.plugin.examples:custom-plugin:[unknown-version]: Could not find ar
tifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ l
ine 7, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:spring-hibernate:[unknown-version](C:devHotswapAgentExamplesspring-hi
bernatepom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-vers
ion]: Could not find artifact org.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT and 'parent.relativePath' points
at wrong local POM @ org.hotswap.agent.examples:hotswap-agent-examples-servlet-parent:[unknown-version], C:\dev\Hot
swapAgentExamples\hotswap-agent-examples-servlet-parent\pom.xml, line 5, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:seam-hibernate-jsf:[unknown-version](C:devHotswapAgentExamplesseam-hi
bernate-jsfpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.examples:seam-hibernate-jsf:[unknown-version]: Failure to find org
.hotswap.agent:hotswap-agent-parent:pom:0.2.1-SNAPSHOT in http://snapshots.jboss.org/maven2/ was cached in the local rep
ository, resolution will not be reattempted until the update interval of snapshots.jboss.org has elapsed or updates are
forced and 'parent.relativePath' points at wrong local POM @ line 6, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:cdi-hibernate-jsf:[unknown-version](C:devHotswapAgentExamplescdi-hibe
rnate-jsfpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.examples:cdi-hibernate-jsf:[unknown-version]: Could not find artif
act org.hotswap.agent:hotswap-agent-parent:pom:0.3.0-SNAPSHOT and 'parent.relativePath' points at wrong local POM @ line
6, column 13 -> [Help 2]
[ERROR]
[ERROR] The project org.hotswap.examples:ejb-cdi-hibernate-jsf:[unknown-version](C:devHotswapAgentExamplesejb-
cdi-hibernate-jsfpom.xml) has 1 error
[ERROR] Non-resolvable parent POM for org.hotswap.examples:ejb-cdi-hibernate-jsf:[unknown-version]: Failure to find
org.hotswap.agent:hotswap-agent-parent:pom:0.3.0-SNAPSHOT in https://repository.jboss.org/nexus/content/groups/public/ w
as cached in the local repository, resolution will not be reattempted until the update interval of JBoss Repository has
elapsed or updates are forced and 'parent.relativePath' points at wrong local POM @ line 6, column 13 -> [Help 2]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/UnresolvableModelException
I get the above warning when I set my pluginPackages variable to the correct package where I created a plugin. I am using the latest DCEVM.
How to disable it? setting LOGGER=OFF has no effect
LOGGER=ERROR does not suit me, i got lots of errors which I have to scroll to find my stack trace
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.