GithubHelp home page GithubHelp logo

magic's Introduction

magic

用于平滑替换运行中 Java 进程的代码。

Class definition for smooth replacement of running Java processes.

使用该 agent 可以在不重启进程的情况下修改代码,并且立即生效。支持从本地路径或远程url加载新的class文件替换堆内存中的class。

The agent can modify the code without restarting the process and take effect immediately.

前提条件

Java应用进程必须设置Can-Retransform-Classes = true,如果使用 maven 打包,可以在 pom.xml 中进行如下配置:

Java application process must set 'can retransform classes = true'. If Maven is used for packaging, you can use the pom.xml The configuration is as follows:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-shade-plugin</artifactId>
            <executions>
                <execution>
                    <phase>package</phase>
                    <goals>
                        <goal>shade</goal>
                    </goals>
            <configuration>
                <transformers>
                    <transformer
                            implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                        <manifestEntries>
                            <Can-Redefine-Classes>true</Can-Redefine-Classes>
                            <Can-Retransform-Classes>true</Can-Retransform-Classes>
                        </manifestEntries>
                    </transformer>
                </transformers>
            </configuration>
        </execution>
    </executions>
        </plugin>
    </plugins>
</build>

如何使用

maven打包后,执行 java -jar magic-1.0.0.jar

run java -jar magic-1.0.0.jar

按照提示依次输入“进程ID”、“全限定类名”、“替换用的class文件地址”、“日志文件全路径”。示例如下:

entry a PID from upper:1234
className:java.lang.String
classPath:/classdir/String.class
logfile:/logdir/example.log

也可以通过启动参数的形势传递,如:

java -jar magic-1.0.0.jar 1234 java.lang.String /classdir/String.class /logdir/example.log

如果正常执行结束将会看到如下信息:

attaching...
loadAgent...
agent loaded!
detaching...
detached!

详细的执行日志可以通过日志文件查看,执行过程中的异常信息也会记录在日志文件中。

magic's People

Contributors

pengten avatar pengtenyang avatar ybhass avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.