Closed lorenzoferrante closed 2 years ago
Could you try --add-opens java.base/java.net=ALL-UNNAMED
?
I've added --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED
and now the errors are gone and when I edit a class it gives me this log:
HOTSWAP AGENT: 17:36:21.146 RELOAD (org.hotswap.agent.config.PluginManager) - Reloading classes [com.lorenzoferrante.demo.HelloServlet] (autoHotswap)
so I assume it's working, but sadly nothing is happening in the webapp
Edit: If you want to see my repo to check my setup here it is: https://github.com/lorenzoferrante/docker_hotswap
Are you using -XX:+AllowEnhancedClassRedefinition
?
You can also use -XX:HotswapAgent=external
(and pby --add-opens=...
is not necessary).
Yes, here's all my java opts:
ENV JAVA_OPTS="-XX:+AllowEnhancedClassRedefinition -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -javaagent:/opt/hotswap-agent/hotswap-agent.jar -Dextra.class.path=/extra_class_path -Dwebapp.dir=/webapp_dir --add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens java.desktop/com.sun.beans.introspect=ALL-UNNAMED --add-opens java.desktop/com.sun.beans.util=ALL-UNNAMED --add-exports java.desktop/com.sun.beans.util=ALL-UNNAMED --add-exports java.base/java.net=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED"
Is the standard redefinition working?
I'm sorry, what do you mean by standard redefinition?
If the hotswap is working without HotswapAgent+AllowEnhancedClassRedefinition - in standard JVM without any addition.
Oh I'm sorry, yes it's working for example with Java 11 + Tomcat in Intellij but the dockerized container with jbr17.0.1 + HotswapAgent is not.
No problem, did you see https://github.com/HotswapProjects/hotswap-docklands ?
Yes, that's what I'm using as a base. I built the same environment but instead I installed JBR with JCEF (DCEVM) from JetBrainsRuntime.
Here's my Dockerfile:
FROM jetbrains/runtime:jbr17env
RUN curl -L -o /jdk17.0.1.tar.gz "https://cache-redirector.jetbrains.com/intellij-jbr/jbr_dcevm-17-linux-x64-b135.1.tar.gz"
RUN tar -xvf /jdk17.0.1.tar.gz
RUN mv /jbr /jdk17.0.1
# Set JDK 17.0.1
ENV JAVA_HOME="/jdk17.0.1"
ENV PATH="${JAVA_HOME}/bin:$PATH"
# Install HotSwap Agent
RUN mkdir -p /opt/hotswap-agent/ \
&& curl -L -o /opt/hotswap-agent/hotswap-agent-1.4.2-SNAPSHOT.jar "https://github.com/HotswapProjects/HotswapAgent/releases/download/1.4.2-SNAPSHOT/hotswap-agent-1.4.2-SNAPSHOT.jar" \
&& ln -f -s /opt/hotswap-agent/hotswap-agent-1.4.2-SNAPSHOT.jar /opt/hotswap-agent/hotswap-agent.jar
# Set up Tomcat
ENV ARCHIVE apache-tomcat-8.5.73
ENV INSTALL_DIR /opt
ENV SERVER_HOME ${INSTALL_DIR}/${ARCHIVE}
RUN curl -o ${SERVER_HOME}.zip -L http://apache.mirror.iphh.net/tomcat/tomcat-8/v8.5.73/bin/apache-tomcat-8.5.73.zip
RUN unzip ${SERVER_HOME}.zip -d /opt
RUN chmod a+x ${SERVER_HOME}/bin/catalina.sh
ENV DEPLOYMENT_DIR ${SERVER_HOME}/webapps/
ENTRYPOINT ${SERVER_HOME}/bin/catalina.sh run
EXPOSE 8080
RUN mkdir -p /extra_class_path
COPY ./target/demo-1.0-SNAPSHOT.war ${DEPLOYMENT_DIR}
EXPOSE 8000
ENV JAVA_OPTS="-XX:+AllowEnhancedClassRedefinition -agentlib:jdwp=transport=dt_socket,server=y,address=8000,suspend=n -javaagent:/opt/hotswap-agent/hotswap-agent.jar -Dextra.class.path=/extra_class_path -Dwebapp.dir=/webapp_dir --add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens java.desktop/com.sun.beans.introspect=ALL-UNNAMED --add-opens java.desktop/com.sun.beans.util=ALL-UNNAMED --add-exports java.desktop/com.sun.beans.util=ALL-UNNAMED --add-exports java.base/java.net=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.desktop/java.beans=ALL-UNNAMED"
Here's my launch script:
#!/bin/sh
mvn clean package && docker build -t jetbrains/runtime:jbr17env .
docker run -ti --rm -p 8080:8080 -p 8000:8000 -v `pwd`/target/classes:/extra_class_path -v /var/run/docker.sock:/var/run/docker.sock jetbrains/runtime:jbr17env
Is there hotswap-agent.properties
in demo-1.0-SNAPSHOT.war
?
https://github.com/skybber/ping/blob/master/src/main/resources/hotswap-agent.properties
Problem solved. I was updating a variable inside the init
method:
public void init() {
message = "Hello World!";
}
and probably that's not possible.
Once I moved the variable in the doGet
method everything is working fine.
We can close this issue. Thank you so much for your help!
I'm trying to use HotSwap Agent with JBR 17.0.1 and I'm using hotswap-agent-1.4.2-SNAPSHOT.jar. When I run the app this is the errors I get:
And also:
These are the java opts:
How can I fix these errors?
Thank you very much